Submission #1556157
Source Code Expand
#include <algorithm> #include <cassert> #include <cstdio> #include <functional> #include <map> #include <numeric> #include <set> #include <vector> #define repeat(i, n) for (int i = 0; (i) < int(n); ++(i)) #define whole(x) begin(x), end(x) using namespace std; int solve(int n, vector<int> const & a, vector<int> const & b) { if (a == b) { return 0; } int sum_a = accumulate(whole(a), 0, bit_xor<int>()); int removed; { map<int, int> cnt; for (int a_i : a) { cnt[a_i] += 1; } cnt[sum_a] += 1; for (int b_i : b) { if (cnt.count(b_i)) { cnt[b_i] -= 1; if (cnt[b_i] == 0) { cnt.erase(b_i); } } } assert (not cnt.empty()); if (cnt.size() >= 2 or cnt.begin()->second >= 2) { assert (false); return -1; // impossible } removed = cnt.begin()->first; } int mismatch = 0; repeat (i, n) { mismatch += (a[i] != b[i]); } int component = 0; { map<int, set<int> > g; repeat (i, n) { if (a[i] != b[i]) { g[b[i]].insert(a[i]); } } set<int> used; function<void (int)> go = [&](int a_i) { used.insert(a_i); for (int a_j : g[a_i]) if (not used.count(a_j)) { go(a_j); } }; repeat (i, n) if (not used.count(a[i])) { if (not g.count(a[i])) continue; component += 1; go(a[i]); } } return mismatch + component - (find(whole(b), sum_a) != b.end()); } int main() { int n; scanf("%d", &n); vector<int> a(n); repeat (i, n) scanf("%d", &a[i]); vector<int> b(n); repeat (i, n) scanf("%d", &b[i]); int result = solve(n, a, b); printf("%d\n", result); return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - XOR Replace |
User | kimiyuki |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1979 Byte |
Status | RE |
Exec Time | 279 ms |
Memory | 25984 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:67:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] int n; scanf("%d", &n); ^ ./Main.cpp:68:55: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] vector<int> a(n); repeat (i, n) scanf("%d", &a[i]); ^ ./Main.cpp:69:55: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] vector<int> b(n); repeat (i, n) scanf("%d", &b[i]); ^
Judge Result
Set Name | Sample | All | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 1000 | ||||||||||
Status |
|
|
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 | RE | 96 ms | 256 KB |
0_03.txt | AC | 1 ms | 256 KB |
1_00.txt | AC | 1 ms | 256 KB |
1_01.txt | RE | 96 ms | 256 KB |
1_02.txt | RE | 96 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 | 19 ms | 1024 KB |
1_08.txt | AC | 151 ms | 25984 KB |
1_09.txt | AC | 150 ms | 19712 KB |
1_10.txt | AC | 25 ms | 1024 KB |
1_11.txt | RE | 117 ms | 1024 KB |
1_12.txt | AC | 25 ms | 1024 KB |
1_13.txt | AC | 25 ms | 1024 KB |
1_14.txt | AC | 32 ms | 1024 KB |
1_15.txt | RE | 122 ms | 1024 KB |
1_16.txt | AC | 32 ms | 1024 KB |
1_17.txt | RE | 124 ms | 1024 KB |
1_18.txt | AC | 39 ms | 1024 KB |
1_19.txt | RE | 125 ms | 1024 KB |
1_20.txt | AC | 38 ms | 1024 KB |
1_21.txt | RE | 125 ms | 1024 KB |
1_22.txt | AC | 54 ms | 1792 KB |
1_23.txt | RE | 128 ms | 1024 KB |
1_24.txt | AC | 54 ms | 1792 KB |
1_25.txt | RE | 130 ms | 1024 KB |
1_26.txt | AC | 78 ms | 4864 KB |
1_27.txt | RE | 136 ms | 1024 KB |
1_28.txt | AC | 80 ms | 4992 KB |
1_29.txt | RE | 137 ms | 1024 KB |
1_30.txt | AC | 96 ms | 6016 KB |
1_31.txt | RE | 143 ms | 1152 KB |
1_32.txt | AC | 97 ms | 6016 KB |
1_33.txt | RE | 144 ms | 1152 KB |
1_34.txt | AC | 117 ms | 7168 KB |
1_35.txt | RE | 153 ms | 1408 KB |
1_36.txt | AC | 116 ms | 7040 KB |
1_37.txt | RE | 153 ms | 1408 KB |
1_38.txt | AC | 163 ms | 11136 KB |
1_39.txt | RE | 172 ms | 2432 KB |
1_40.txt | AC | 161 ms | 11136 KB |
1_41.txt | RE | 171 ms | 2432 KB |
1_42.txt | AC | 216 ms | 16896 KB |
1_43.txt | RE | 189 ms | 4352 KB |
1_44.txt | AC | 231 ms | 17152 KB |
1_45.txt | RE | 188 ms | 4352 KB |
1_46.txt | AC | 257 ms | 20224 KB |
1_47.txt | RE | 195 ms | 5248 KB |
1_48.txt | AC | 257 ms | 20352 KB |
1_49.txt | RE | 198 ms | 5248 KB |
1_50.txt | WA | 253 ms | 21248 KB |
1_51.txt | RE | 196 ms | 5376 KB |
1_52.txt | AC | 264 ms | 21376 KB |
1_53.txt | RE | 198 ms | 5504 KB |
1_54.txt | WA | 257 ms | 21504 KB |
1_55.txt | RE | 196 ms | 5504 KB |
1_56.txt | AC | 279 ms | 21632 KB |
1_57.txt | RE | 200 ms | 5632 KB |
1_58.txt | WA | 261 ms | 21888 KB |
1_59.txt | RE | 200 ms | 5632 KB |
1_60.txt | AC | 262 ms | 22016 KB |
1_61.txt | RE | 199 ms | 5632 KB |
1_62.txt | WA | 267 ms | 21632 KB |
1_63.txt | RE | 194 ms | 5504 KB |
1_64.txt | AC | 255 ms | 21248 KB |
1_65.txt | RE | 198 ms | 5632 KB |
1_66.txt | WA | 256 ms | 22784 KB |
1_67.txt | RE | 198 ms | 5632 KB |
1_68.txt | AC | 264 ms | 24576 KB |
1_69.txt | RE | 199 ms | 5632 KB |