結果

問題 No.1209 XOR Into You
ユーザー rabimearabimea
提出日時 2023-01-28 02:04:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 335 ms / 2,000 ms
コード長 1,501 bytes
コンパイル時間 2,273 ms
コンパイル使用メモリ 214,552 KB
実行使用メモリ 27,928 KB
最終ジャッジ日時 2023-09-10 18:59:07
合計ジャッジ時間 14,950 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 26 ms
4,376 KB
testcase_05 AC 26 ms
4,376 KB
testcase_06 AC 208 ms
26,072 KB
testcase_07 AC 271 ms
23,908 KB
testcase_08 AC 240 ms
22,044 KB
testcase_09 AC 242 ms
22,008 KB
testcase_10 AC 190 ms
17,940 KB
testcase_11 AC 244 ms
21,652 KB
testcase_12 AC 225 ms
20,700 KB
testcase_13 AC 265 ms
22,836 KB
testcase_14 AC 214 ms
20,112 KB
testcase_15 AC 233 ms
20,924 KB
testcase_16 AC 225 ms
20,588 KB
testcase_17 AC 216 ms
20,120 KB
testcase_18 AC 335 ms
26,804 KB
testcase_19 AC 231 ms
20,576 KB
testcase_20 AC 265 ms
23,080 KB
testcase_21 AC 184 ms
17,652 KB
testcase_22 AC 155 ms
27,928 KB
testcase_23 AC 156 ms
27,816 KB
testcase_24 AC 159 ms
27,836 KB
testcase_25 AC 279 ms
27,792 KB
testcase_26 AC 284 ms
27,648 KB
testcase_27 AC 280 ms
27,576 KB
testcase_28 AC 278 ms
27,720 KB
testcase_29 AC 289 ms
27,756 KB
testcase_30 AC 287 ms
27,860 KB
testcase_31 AC 147 ms
7,172 KB
testcase_32 AC 148 ms
7,296 KB
testcase_33 AC 147 ms
7,236 KB
testcase_34 AC 148 ms
7,092 KB
testcase_35 AC 147 ms
7,232 KB
testcase_36 AC 147 ms
7,376 KB
testcase_37 AC 66 ms
6,568 KB
testcase_38 AC 216 ms
23,812 KB
testcase_39 AC 192 ms
21,688 KB
testcase_40 AC 158 ms
27,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
using vi = vector <int>;
using ll = long long;
using vl = vector <ll>;
using pii = pair <int, int>;
//~ const ll mod = 998244353;
const ll mod = 1e9 + 7;
ll qpow(ll a, ll b, ll m = mod) { ll r = 1, t = a;
	for(; b; b /= 2) { if(b & 1) r = r * t % m; t = t * t % m; } return r; }

const int N = 2e5 + 11;

int a[N], b[N];

int p[N];

struct event {
	int x, t;
	bool operator <(const event &e) const {
		return x < e.x;
	}
};
ll solve(int l, int r) {
	if(l + 1 == r) return 0;
	int m = (l + r) / 2;
	ll re = solve(l, m) + solve(m, r);
	vector <event> es;
	for(int i = l; i < m; i ++)
		es.pb({p[i], 0});
	for(int i = m; i < r; i ++)
		es.pb({p[i], 1});
	
	int cnt = 0;
	sort(es.begin(), es.end());
	for(auto e : es)
		if(e.t == 1) cnt ++;
		else re += cnt;
	return re;
}

int main() {
	ios :: sync_with_stdio(false);
	
	int n; cin >> n;
	for(int i = 0; i < n; i ++) cin >> a[i];
	for(int i = 0; i < n; i ++) cin >> b[i];
	
	if(a[0] != b[0]) {
		cout << "-1\n";
		return 0;
	}
	
	map <int, vi> ma, mb;
	for(int i = 0; i < n - 1; i ++) {
		ma[a[i] ^ a[i + 1]].pb(i);
		mb[b[i] ^ b[i + 1]].pb(i);
	}

	for(auto &[x, u] : ma) {
		auto &v = mb[x];
		if(u.size() != v.size()) {
			cout << "-1\n";
			return 0;
		}
		
		for(int i = 0; i < u.size(); i ++) {
			p[u[i]] = v[i];
		}
	}
	
	//~ for(int i = 0; i < n - 1; i ++)
		//~ cout << p[i] << ' ';
	//~ cout << '\n';
	
	cout << solve(0, n - 1) << '\n';
}
0