結果

問題 No.1209 XOR Into You
ユーザー ianCKianCK
提出日時 2020-09-23 17:37:02
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,230 bytes
コンパイル時間 2,040 ms
コンパイル使用メモリ 46,612 KB
実行使用メモリ 9,732 KB
最終ジャッジ日時 2023-09-10 07:21:33
合計ジャッジ時間 9,637 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 67 ms
9,584 KB
testcase_05 WA -
testcase_06 AC 67 ms
9,648 KB
testcase_07 AC 88 ms
8,592 KB
testcase_08 AC 81 ms
8,100 KB
testcase_09 AC 78 ms
8,244 KB
testcase_10 AC 60 ms
7,260 KB
testcase_11 AC 75 ms
8,092 KB
testcase_12 AC 69 ms
7,720 KB
testcase_13 AC 80 ms
8,384 KB
testcase_14 AC 68 ms
7,660 KB
testcase_15 AC 70 ms
7,912 KB
testcase_16 AC 71 ms
7,752 KB
testcase_17 AC 65 ms
7,624 KB
testcase_18 AC 102 ms
9,400 KB
testcase_19 AC 69 ms
7,840 KB
testcase_20 AC 84 ms
8,328 KB
testcase_21 AC 59 ms
7,244 KB
testcase_22 AC 61 ms
9,700 KB
testcase_23 AC 60 ms
9,732 KB
testcase_24 AC 61 ms
9,640 KB
testcase_25 AC 93 ms
9,732 KB
testcase_26 AC 91 ms
9,704 KB
testcase_27 AC 94 ms
9,636 KB
testcase_28 AC 94 ms
9,708 KB
testcase_29 AC 94 ms
9,700 KB
testcase_30 AC 91 ms
9,644 KB
testcase_31 AC 99 ms
9,620 KB
testcase_32 AC 99 ms
9,704 KB
testcase_33 AC 101 ms
9,708 KB
testcase_34 AC 100 ms
9,680 KB
testcase_35 AC 100 ms
9,620 KB
testcase_36 AC 100 ms
9,644 KB
testcase_37 AC 58 ms
9,620 KB
testcase_38 AC 77 ms
8,624 KB
testcase_39 AC 68 ms
8,060 KB
testcase_40 AC 61 ms
9,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <utility>
#include <string.h>
#include <set>
using namespace std;

#define F first
#define S second

typedef long long int ll;
constexpr int kN = int(1E5 + 10);

int ABS(int n) {return n >= 0 ? n : -n;}

struct BIT {
	int val[kN];
	void init() {memset(val, 0, sizeof(val));}
	void add(int pos) {
		while (pos < kN) {
			val[pos]++;
			pos += pos & -pos;
		}
		return ;
	}
	int ask(int pos) {
		int ans = 0;
		while (pos) {
			ans += val[pos];
			pos ^= pos & -pos;
		}
		return ans;
	}
};


int a[kN], b[kN], difa[kN], difb[kN];
set<pair<int, int>> se;
BIT bit;

int main() {
	int n;
	ll ans = 0;
	set<pair<int, int>>::iterator u;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
	for (int i = 2; i <= n; i++) difa[i] = a[i] ^ a[i - 1];
	for (int i = 2; i <= n; i++) difb[i] = b[i] ^ b[i - 1];
	for (int i = 2; i <= n; i++) se.insert({difa[i], i});
	bit.init();
	for (int i = 2; i <= n; i++) {
		u = se.lower_bound({difb[i], 0});
		if (u == se.end() || u -> F != difb[i]) {
			printf("-1\n");
			return 0;
		}
		else {
			ans += ABS(u -> S - bit.ask(u -> S) - 2);
			bit.add(u -> S);
			se.erase(u);
		}
	}
	printf("%lld\n", ans);
}
0