Submission #1163059


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);
	
	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;
		
		int pos = 0;
		while (d >= n - pos - 1) {
			a[n - pos - 1] = pos + 1;
			d -= n - pos - 1;
			pos++;
		}
		REP(i, n - pos) a[i] = i + 1 + pos;
		
		FOR(i, 1, n - pos) {
			if (d == 0) break;
			
			swap(a[i], a[i - 1]);
		}
		
		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
Task C - 転倒距離
User tkmst201
Language C++ (GCC 5.4.1)
Score 0
Code Size 2261 Byte
Status WA
Exec Time 35 ms
Memory 2816 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
AC × 1
WA × 2
AC × 11
WA × 11
AC × 20
WA × 21
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 WA 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 2 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 2 ms 768 KB
subtask1_10.txt AC 2 ms 768 KB
subtask1_11.txt WA 2 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 2 ms 768 KB
subtask1_17.txt AC 2 ms 768 KB
subtask1_18.txt WA 2 ms 768 KB
subtask1_19.txt WA 2 ms 768 KB
subtask2_01.txt AC 5 ms 896 KB
subtask2_02.txt WA 27 ms 2304 KB
subtask2_03.txt WA 32 ms 2688 KB
subtask2_04.txt AC 14 ms 1536 KB
subtask2_05.txt AC 19 ms 1920 KB
subtask2_06.txt AC 12 ms 1408 KB
subtask2_07.txt AC 20 ms 1920 KB
subtask2_08.txt WA 32 ms 2688 KB
subtask2_09.txt AC 14 ms 1536 KB
subtask2_10.txt AC 13 ms 1408 KB
subtask2_11.txt WA 15 ms 1536 KB
subtask2_12.txt AC 24 ms 2176 KB
subtask2_13.txt WA 34 ms 2816 KB
subtask2_14.txt AC 22 ms 2048 KB
subtask2_15.txt WA 34 ms 2816 KB
subtask2_16.txt WA 34 ms 2816 KB
subtask2_17.txt WA 35 ms 2816 KB
subtask2_18.txt WA 34 ms 2816 KB
subtask2_19.txt WA 34 ms 2816 KB