Submission #1162752
Source Code Expand
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
#include <ctime>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;
typedef vector<pii> vp;
#define INF (1<<29)
#define INFL (1ll<<60)
#define EPS (1e-8)
#define PI (acos(-1))
const ll MOD = 1000000007ll;
template<typename T> struct BIT {
vector<T> bit;
int n;
BIT() {}
BIT(int n) : bit(vector<T>(n + 2, 0)), n(n) {}
T sum(int i) {
i++;
T s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, T x) {
i++;
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
int lower_bound(T x) {
int l = 0, r = bit.size() + 1;
while (r - l > 1) {
int m = (l + r) / 2;
if (sum(m) >= x) r = m;
else l = m;
}
if (r == bit.size() + 1) r = -1;
return r;
}
};
int n;
int a[112345], b[112345];
int pos[112345];
ll count(int a[], int b[]) {
REP(i, n) pos[a[i]] = i;
BIT<int> bit(112345);
REP(i, n) bit.add(i, 1);
ll res = 0;
for (int i = n - 1; i >= 0; i--) {
res += bit.sum(112345) - bit.sum(pos[b[i]]);
bit.add(pos[b[i]], -1);
}
return res;
}
int main() {
cin >> n;
REP(i, n) scanf("%d", a + i);
REP(i, n) scanf("%d", b + i);
ll d = count(a, b);
if (d & 1) puts("-1");
else {
int tmp[112345];
REP(i, n) tmp[i] = i + 1;
srand((unsigned int)time(NULL));
REP(i, 50000) {
int r = rand() % n;
int l = rand() % n;
swap(tmp[r], tmp[l]);
if (count(tmp, a) == count(tmp, b)) {
REP(i, n) printf("%d%c", tmp[i], i == n - 1 ? '\n' : ' ');
return 0;
}
}
}
puts("-1");
return 0;
}
Submission Info
Submission Time
2017-03-15 18:36:25+0900
Task
C - 転倒距離
User
tkmst201
Language
C++ (GCC 5.4.1)
Score
0
Code Size
2297 Byte
Status
WA
Exec Time
2103 ms
Memory
2248 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:97:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
REP(i, n) scanf("%d", a + i);
^
./Main.cpp:98:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
REP(i, n) scanf("%d", b + i);
^
Judge Result
Set Name
Sample
Subtask1
Subtask2
Score / Max Score
0 / 0
0 / 30
0 / 70
Status
Set Name
Test Cases
Sample
sample_01.txt, sample_02.txt, sample_03.txt
Subtask1
sample_01.txt, sample_02.txt, sample_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt
Subtask2
sample_01.txt, sample_02.txt, sample_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.txt, subtask2_14.txt, subtask2_15.txt, subtask2_16.txt, subtask2_17.txt, subtask2_18.txt, subtask2_19.txt
Case Name
Status
Exec Time
Memory
sample_01.txt
AC
2 ms
712 KB
sample_02.txt
WA
1 ms
640 KB
sample_03.txt
AC
2 ms
712 KB
subtask1_01.txt
WA
2 ms
768 KB
subtask1_02.txt
TLE
2103 ms
768 KB
subtask1_03.txt
AC
734 ms
768 KB
subtask1_04.txt
TLE
2103 ms
768 KB
subtask1_05.txt
WA
2 ms
768 KB
subtask1_06.txt
WA
1 ms
640 KB
subtask1_07.txt
AC
615 ms
712 KB
subtask1_08.txt
WA
1 ms
640 KB
subtask1_09.txt
AC
1018 ms
768 KB
subtask1_10.txt
WA
2 ms
640 KB
subtask1_11.txt
TLE
2103 ms
768 KB
subtask1_12.txt
WA
2 ms
768 KB
subtask1_13.txt
WA
2 ms
768 KB
subtask1_14.txt
WA
2 ms
768 KB
subtask1_15.txt
WA
2 ms
768 KB
subtask1_16.txt
TLE
2103 ms
768 KB
subtask1_17.txt
WA
2 ms
768 KB
subtask1_18.txt
TLE
2103 ms
768 KB
subtask1_19.txt
TLE
2103 ms
768 KB
subtask2_01.txt
WA
5 ms
896 KB
subtask2_02.txt
TLE
2103 ms
1864 KB
subtask2_03.txt
TLE
2103 ms
2120 KB
subtask2_04.txt
WA
15 ms
1280 KB
subtask2_05.txt
WA
21 ms
1536 KB
subtask2_06.txt
WA
12 ms
1152 KB
subtask2_07.txt
WA
22 ms
1664 KB
subtask2_08.txt
TLE
2103 ms
2120 KB
subtask2_09.txt
WA
15 ms
1280 KB
subtask2_10.txt
WA
14 ms
1280 KB
subtask2_11.txt
TLE
2103 ms
1352 KB
subtask2_12.txt
WA
26 ms
1792 KB
subtask2_13.txt
TLE
2103 ms
2248 KB
subtask2_14.txt
WA
23 ms
1664 KB
subtask2_15.txt
TLE
2103 ms
2248 KB
subtask2_16.txt
TLE
2103 ms
2248 KB
subtask2_17.txt
TLE
2103 ms
2248 KB
subtask2_18.txt
TLE
2103 ms
2248 KB
subtask2_19.txt
TLE
2103 ms
2248 KB