# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
307831 | 2020-09-29T11:21:46 Z | AlexLuchianov | 카멜레온의 사랑 (JOI20_chameleon) | C++14 | 84 ms | 384 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; do { int x = 0; 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; 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 36 ms | 384 KB | Output is correct |
4 | Correct | 36 ms | 384 KB | Output is correct |
5 | Correct | 36 ms | 384 KB | Output is correct |
6 | Correct | 36 ms | 384 KB | Output is correct |
7 | Correct | 38 ms | 384 KB | Output is correct |
8 | Correct | 36 ms | 384 KB | Output is correct |
9 | Correct | 37 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 1 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 0 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 1 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 384 KB | Output is correct |
8 | Correct | 1 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 | 2 ms | 384 KB | Output is correct |
13 | Correct | 2 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 | 2 ms | 384 KB | Output is correct |
18 | Correct | 2 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Incorrect | 84 ms | 384 KB | Wrong Answer [3] |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 36 ms | 384 KB | Output is correct |
4 | Correct | 36 ms | 384 KB | Output is correct |
5 | Correct | 36 ms | 384 KB | Output is correct |
6 | Correct | 36 ms | 384 KB | Output is correct |
7 | Correct | 38 ms | 384 KB | Output is correct |
8 | Correct | 36 ms | 384 KB | Output is correct |
9 | Correct | 37 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 | 1 ms | 384 KB | Output is correct |
14 | Correct | 0 ms | 384 KB | Output is correct |
15 | Correct | 0 ms | 384 KB | Output is correct |
16 | Correct | 0 ms | 384 KB | Output is correct |
17 | Correct | 1 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 | 2 ms | 384 KB | Output is correct |
22 | Correct | 2 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 | 2 ms | 384 KB | Output is correct |
27 | Correct | 2 ms | 384 KB | Output is correct |
28 | Correct | 1 ms | 384 KB | Output is correct |
29 | Correct | 0 ms | 384 KB | Output is correct |
30 | Incorrect | 84 ms | 384 KB | Wrong Answer [3] |
31 | Halted | 0 ms | 0 KB | - |