# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
307834 | 2020-09-29T11:29:01 Z | AlexLuchianov | Chameleon's Love (JOI20_chameleon) | C++14 | 83 ms | 508 KB |
#include "chameleon.h" #include <vector> #include <algorithm> #include <cassert> #include <iostream> namespace { int const sets = 4; std::vector<std::vector<int>> g; void add_edge(int x, int y) { g[x].push_back(y); g[y].push_back(x); } std::vector<int> reunion(std::vector<int> a, std::vector<int> b) { for(int i = 0; i < b.size(); i++) a.push_back(b[i]); return a; } int query(std::vector<int> a) { return Query(a); } std::vector<int> pref(std::vector<int> a, int k) { if(a.size() <= k) return a; else { std::vector<int> result; for(int i = 0; i < k; i++) result.push_back(a[i]); return result; } } std::vector<std::pair<int,int>> get_all_edges(std::vector<int> a, int node) { std::vector<std::pair<int,int>> edges; int x = 0; do { for(int jump = (1 << 10); 0 < jump; jump /= 2) { if(x + jump < a.size() && query(reunion(pref(a, x + jump), {node})) == x + jump + 1) x += jump; } edges.push_back({a[x], node}); a.erase(a.begin() + x); } while(query(reunion(a, {node})) < a.size() + 1); return edges; } } void Solve(int n) { std::vector<std::vector<int>> independent_set(sets); g.resize(1 + 2 * n); for(int i = 1; i <= 2 * n; i++) { int ptr = 0; for(int j = 0; j < sets; j++) { if(j == sets - 1 || query(reunion(independent_set[j], {i})) == independent_set[j].size() + 1) { independent_set[j].push_back(i); ptr = j; break; } } for(int j = 0; j < sets - 1; j++) if(find(independent_set[j].begin(), independent_set[j].end(), i) == independent_set[j].end()) { if(j < ptr) { std::vector<std::pair<int,int>> edges = get_all_edges(independent_set[j], i); for(int h = 0; h < edges.size(); h++) add_edge(edges[h].first, edges[h].second); } else if(query(reunion(independent_set[j], {i})) < independent_set[j].size() + 1) { std::vector<std::pair<int,int>> edges = get_all_edges(independent_set[j], i); for(int h = 0; h < edges.size(); h++) add_edge(edges[h].first, edges[h].second); } } } std::vector<int> connect(2 * n + 1); for(int i = 1; i <= 2 * n; i++) { assert(g[i].size() == 1 || g[i].size() == 3); if(g[i].size() == 3) { connect[i] += g[i][0] + g[i][1] + g[i][2]; if(query({i, g[i][0], g[i][1]}) == 1) { connect[i] -= g[i][2]; connect[g[i][2]] -= i; } else if (query({i, g[i][0], g[i][2]}) == 1) { connect[i] -= g[i][1]; connect[g[i][1]] -= i; } else { connect[i] -= g[i][0]; connect[g[i][0]] -= i; } } else connect[i] += g[i][0]; } for (int i = 1; i <= 2 * n; i++) if(i < connect[i]) Answer(i, connect[i]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 32 ms | 384 KB | Output is correct |
4 | Correct | 32 ms | 384 KB | Output is correct |
5 | Correct | 37 ms | 384 KB | Output is correct |
6 | Correct | 32 ms | 508 KB | Output is correct |
7 | Correct | 32 ms | 384 KB | Output is correct |
8 | Correct | 32 ms | 384 KB | Output is correct |
9 | Correct | 32 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
4 | Correct | 0 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 384 KB | Output is correct |
8 | Correct | 0 ms | 384 KB | Output is correct |
9 | Correct | 0 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
4 | Correct | 0 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 384 KB | Output is correct |
8 | Correct | 0 ms | 384 KB | Output is correct |
9 | Correct | 0 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 384 KB | Output is correct |
12 | Correct | 1 ms | 384 KB | Output is correct |
13 | Correct | 1 ms | 384 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
16 | Correct | 2 ms | 384 KB | Output is correct |
17 | Correct | 1 ms | 384 KB | Output is correct |
18 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 74 ms | 384 KB | Output is correct |
4 | Correct | 83 ms | 384 KB | Output is correct |
5 | Correct | 74 ms | 384 KB | Output is correct |
6 | Correct | 74 ms | 384 KB | Output is correct |
7 | Correct | 75 ms | 444 KB | Output is correct |
8 | Correct | 74 ms | 384 KB | Output is correct |
9 | Correct | 74 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 32 ms | 384 KB | Output is correct |
4 | Correct | 32 ms | 384 KB | Output is correct |
5 | Correct | 37 ms | 384 KB | Output is correct |
6 | Correct | 32 ms | 508 KB | Output is correct |
7 | Correct | 32 ms | 384 KB | Output is correct |
8 | Correct | 32 ms | 384 KB | Output is correct |
9 | Correct | 32 ms | 384 KB | Output is correct |
10 | Correct | 0 ms | 384 KB | Output is correct |
11 | Correct | 0 ms | 384 KB | Output is correct |
12 | Correct | 0 ms | 384 KB | Output is correct |
13 | Correct | 0 ms | 384 KB | Output is correct |
14 | Correct | 0 ms | 384 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
16 | Correct | 0 ms | 384 KB | Output is correct |
17 | Correct | 0 ms | 384 KB | Output is correct |
18 | Correct | 0 ms | 384 KB | Output is correct |
19 | Correct | 1 ms | 384 KB | Output is correct |
20 | Correct | 1 ms | 384 KB | Output is correct |
21 | Correct | 1 ms | 384 KB | Output is correct |
22 | Correct | 1 ms | 384 KB | Output is correct |
23 | Correct | 2 ms | 384 KB | Output is correct |
24 | Correct | 1 ms | 384 KB | Output is correct |
25 | Correct | 2 ms | 384 KB | Output is correct |
26 | Correct | 1 ms | 384 KB | Output is correct |
27 | Correct | 1 ms | 384 KB | Output is correct |
28 | Correct | 1 ms | 384 KB | Output is correct |
29 | Correct | 1 ms | 384 KB | Output is correct |
30 | Correct | 74 ms | 384 KB | Output is correct |
31 | Correct | 83 ms | 384 KB | Output is correct |
32 | Correct | 74 ms | 384 KB | Output is correct |
33 | Correct | 74 ms | 384 KB | Output is correct |
34 | Correct | 75 ms | 444 KB | Output is correct |
35 | Correct | 74 ms | 384 KB | Output is correct |
36 | Correct | 74 ms | 384 KB | Output is correct |
37 | Correct | 58 ms | 384 KB | Output is correct |
38 | Correct | 32 ms | 384 KB | Output is correct |
39 | Correct | 57 ms | 504 KB | Output is correct |
40 | Correct | 58 ms | 384 KB | Output is correct |
41 | Correct | 57 ms | 384 KB | Output is correct |
42 | Correct | 32 ms | 384 KB | Output is correct |
43 | Correct | 74 ms | 384 KB | Output is correct |
44 | Correct | 58 ms | 384 KB | Output is correct |
45 | Correct | 57 ms | 384 KB | Output is correct |