Submission #1163359
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 conv[112345], rev[112345];
int main() {
cin >> n;
REP(i, n) scanf("%d", a + i);
REP(i, n) scanf("%d", b + i);
assert(n <= 3000);
REP(i, n) conv[ a[i] ] = i + 1;
REP(i, n) rev[ i + 1 ] = a[i];
BIT<int> bit(112345);
ll d = 0;
REP(i, n) b[i] = conv[ b[i] ];
REP(i, n) {
d += bit.sum(112345) - bit.sum(b[i]);
bit.add(b[i], 1);
}
if (d & 1) puts("-1");
else {
d /= 2;
REP(i, n) {
if (d == 0) break;
REP(j, n - i - 1) {
if (d == 0) break;
if (a[j] < a[j + 1]) {
swap(a[j], a[j + 1]);
d--;
}
}
}
REP(i, n) a[i] = rev[ a[i] ];
REP(i, n) printf("%d%c", a[i], i == n - 1 ? '\n' : ' ');
}
return 0;
}
Submission Info
Submission Time
2017-03-16 09:50:28+0900
Task
C - 転倒距離
User
tkmst201
Language
C++ (GCC 5.4.1)
Score
0
Code Size
2225 Byte
Status
RE
Exec Time
118 ms
Memory
1024 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:82: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:83: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
1 ms
640 KB
sample_02.txt
AC
1 ms
640 KB
sample_03.txt
WA
1 ms
640 KB
subtask1_01.txt
AC
2 ms
768 KB
subtask1_02.txt
WA
4 ms
768 KB
subtask1_03.txt
WA
2 ms
768 KB
subtask1_04.txt
WA
2 ms
768 KB
subtask1_05.txt
AC
2 ms
768 KB
subtask1_06.txt
AC
1 ms
640 KB
subtask1_07.txt
WA
2 ms
768 KB
subtask1_08.txt
AC
1 ms
640 KB
subtask1_09.txt
WA
3 ms
768 KB
subtask1_10.txt
AC
2 ms
768 KB
subtask1_11.txt
WA
4 ms
768 KB
subtask1_12.txt
AC
2 ms
768 KB
subtask1_13.txt
AC
2 ms
768 KB
subtask1_14.txt
AC
2 ms
768 KB
subtask1_15.txt
AC
2 ms
768 KB
subtask1_16.txt
WA
5 ms
768 KB
subtask1_17.txt
AC
2 ms
768 KB
subtask1_18.txt
WA
5 ms
768 KB
subtask1_19.txt
WA
5 ms
768 KB
subtask2_01.txt
RE
100 ms
384 KB
subtask2_02.txt
RE
110 ms
896 KB
subtask2_03.txt
RE
113 ms
1024 KB
subtask2_04.txt
RE
107 ms
640 KB
subtask2_05.txt
RE
108 ms
896 KB
subtask2_06.txt
RE
103 ms
640 KB
subtask2_07.txt
RE
111 ms
896 KB
subtask2_08.txt
RE
114 ms
1024 KB
subtask2_09.txt
RE
106 ms
640 KB
subtask2_10.txt
RE
105 ms
640 KB
subtask2_11.txt
RE
105 ms
640 KB
subtask2_12.txt
RE
114 ms
1024 KB
subtask2_13.txt
RE
114 ms
1024 KB
subtask2_14.txt
RE
110 ms
896 KB
subtask2_15.txt
RE
116 ms
1024 KB
subtask2_16.txt
RE
115 ms
1024 KB
subtask2_17.txt
RE
118 ms
1024 KB
subtask2_18.txt
RE
115 ms
1024 KB
subtask2_19.txt
RE
113 ms
1024 KB