Contest Duration: - (local time) (110 minutes) Back to Home

Submission #1365639

Source Code Expand

Copy
```#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
struct UnionFind { vector<int> par,cnt;
UnionFind(int NV){par.clear();cnt.resize(NV, 1);rep(i, 0, NV) par.push_back(i); }
int operator[](int x) { return par[x] == x ? x : par[x] = operator[](par[x]); }
void operator()(int x, int y) { x = operator[](x); y = operator[](y);
if (x != y) par[x] = y, cnt[y] += cnt[x]; }};
/*---------------------------------------------------------------------------------------------------
∧＿∧
∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
（ ´_ゝ`）　/　 ⌒i
／　　　＼　 　  |　|
/　　 /￣￣￣￣/　　|
＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

int N, A[101010], B[101010];
//---------------------------------------------------------------------------------------------------
bool chk() {
map<int, int> cnt;
rep(i, 0, N + 1) cnt[A[i]]++;
rep(i, 0, N + 1) { if (cnt[B[i]] == 0) return false; cnt[B[i]]--; }
return true;
}
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N;
rep(i, 0, N) cin >> A[i];
rep(i, 0, N) cin >> B[i];

A[N] = 0;
rep(i, 0, N) A[N] ^= A[i];

B[N] = 0;
rep(i, 0, N) B[N] ^= B[i];

if (!chk()) { printf("-1\n"); return; }

int e = 0, c = 0, d = 0;

if (A[N] != B[N]) {
e++;
rep(i, 0, N) if (A[i] != B[i] && B[i] == A[N]) {
swap(A[i], A[N]);
break;
}
}

vector<int> dic;
rep(i, 0, N) if (A[i] != B[i]) {
c++;
dic.push_back(A[i]);
}
sort(dic.begin(), dic.end());
dic.erase(unique(dic.begin(), dic.end()), dic.end());

UnionFind uf(dic.size());
rep(i, 0, N + 1) if (A[i] != B[i]) {
int a = lower_bound(dic.begin(), dic.end(), A[i]) - dic.begin();
int b = lower_bound(dic.begin(), dic.end(), B[i]) - dic.begin();
uf(a, b);
}

rep(i, 0, dic.size()) if (uf[i] == i) c++;

rep(i, 0, N) if (A[i] != B[i] && B[i] == A[N]) {
d = -1;
break;
}

int ans = e + c + d;
cout << ans << endl;
}```

#### Submission Info

Submission Time 2017-06-19 18:51:00+0900 D - XOR Replace hamayanhamayan C++14 (GCC 5.4.1) 1000 2684 Byte AC 120 ms 5760 KB

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1000 / 1000
Status
 AC × 4
 AC × 74
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt, 1_41.txt, 1_42.txt, 1_43.txt, 1_44.txt, 1_45.txt, 1_46.txt, 1_47.txt, 1_48.txt, 1_49.txt, 1_50.txt, 1_51.txt, 1_52.txt, 1_53.txt, 1_54.txt, 1_55.txt, 1_56.txt, 1_57.txt, 1_58.txt, 1_59.txt, 1_60.txt, 1_61.txt, 1_62.txt, 1_63.txt, 1_64.txt, 1_65.txt, 1_66.txt, 1_67.txt, 1_68.txt, 1_69.txt
Case Name Status Exec Time Memory
0_00.txt AC 1 ms 256 KB
0_01.txt AC 1 ms 256 KB
0_02.txt AC 1 ms 256 KB
0_03.txt AC 1 ms 256 KB
1_00.txt AC 1 ms 256 KB
1_01.txt AC 1 ms 256 KB
1_02.txt AC 1 ms 256 KB
1_03.txt AC 1 ms 256 KB
1_04.txt AC 1 ms 256 KB
1_05.txt AC 1 ms 256 KB
1_06.txt AC 1 ms 256 KB
1_07.txt AC 58 ms 5760 KB
1_08.txt AC 71 ms 5760 KB
1_09.txt AC 70 ms 5760 KB
1_10.txt AC 22 ms 1408 KB
1_11.txt AC 19 ms 1024 KB
1_12.txt AC 22 ms 1408 KB
1_13.txt AC 22 ms 1408 KB
1_14.txt AC 29 ms 1660 KB
1_15.txt AC 24 ms 1024 KB
1_16.txt AC 30 ms 1660 KB
1_17.txt AC 24 ms 1024 KB
1_18.txt AC 36 ms 1660 KB
1_19.txt AC 27 ms 1024 KB
1_20.txt AC 35 ms 1660 KB
1_21.txt AC 27 ms 1024 KB
1_22.txt AC 43 ms 1660 KB
1_23.txt AC 31 ms 1024 KB
1_24.txt AC 42 ms 1660 KB
1_25.txt AC 31 ms 1024 KB
1_26.txt AC 50 ms 1660 KB
1_27.txt AC 39 ms 1024 KB
1_28.txt AC 51 ms 1660 KB
1_29.txt AC 36 ms 1024 KB
1_30.txt AC 59 ms 1660 KB
1_31.txt AC 40 ms 1152 KB
1_32.txt AC 59 ms 1660 KB
1_33.txt AC 40 ms 1152 KB
1_34.txt AC 70 ms 1656 KB
1_35.txt AC 49 ms 1408 KB
1_36.txt AC 69 ms 1656 KB
1_37.txt AC 48 ms 1408 KB
1_38.txt AC 92 ms 2560 KB
1_39.txt AC 53 ms 2560 KB
1_40.txt AC 91 ms 2560 KB
1_41.txt AC 62 ms 2560 KB
1_42.txt AC 109 ms 4224 KB
1_43.txt AC 53 ms 4352 KB
1_44.txt AC 111 ms 4352 KB
1_45.txt AC 57 ms 4352 KB
1_46.txt AC 118 ms 5248 KB
1_47.txt AC 72 ms 5248 KB
1_48.txt AC 119 ms 5376 KB
1_49.txt AC 54 ms 5248 KB
1_50.txt AC 118 ms 5632 KB
1_51.txt AC 58 ms 5504 KB
1_52.txt AC 119 ms 5632 KB
1_53.txt AC 55 ms 5632 KB
1_54.txt AC 119 ms 5632 KB
1_55.txt AC 74 ms 5504 KB
1_56.txt AC 119 ms 5760 KB
1_57.txt AC 66 ms 5760 KB
1_58.txt AC 119 ms 5760 KB
1_59.txt AC 76 ms 5760 KB
1_60.txt AC 119 ms 5760 KB
1_61.txt AC 63 ms 5760 KB
1_62.txt AC 120 ms 5760 KB
1_63.txt AC 73 ms 5504 KB
1_64.txt AC 117 ms 5632 KB
1_65.txt AC 56 ms 5632 KB
1_66.txt AC 118 ms 5632 KB
1_67.txt AC 70 ms 5632 KB
1_68.txt AC 119 ms 5760 KB
1_69.txt AC 54 ms 5760 KB