Submission #307826

#TimeUsernameProblemLanguageResultExecution timeMemory
307826AlexLuchianovChameleon's Love (JOI20_chameleon)C++14
44 / 100
81 ms504 KiB
#include "chameleon.h" #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; while(Query(reunion(a, {node})) < a.size() + 1){ 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); } 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++) { for(int j = 0; j < sets; j++) { if(query(reunion(independent_set[j], {i})) == independent_set[j].size() + 1) { independent_set[j].push_back(i); break; } } for(int j = 0; j < sets; j++) if(find(independent_set[j].begin(), independent_set[j].end(), i) == independent_set[j].end()) { 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; } if(query({i, g[i][0], g[i][2]}) == 1) { connect[i] -= g[i][1]; connect[g[i][1]] -= i; } if(query({i, g[i][2], g[i][1]}) == 1) { 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 (stderr)

chameleon.cpp: In function 'std::vector<int> {anonymous}::reunion(std::vector<int>, std::vector<int>)':
chameleon.cpp:16:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(int i = 0; i < b.size(); i++)
      |                    ~~^~~~~~~~~~
chameleon.cpp: In function 'std::vector<int> {anonymous}::pref(std::vector<int>, int)':
chameleon.cpp:24:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |     if(a.size() <= k)
      |        ~~~~~~~~~^~~~
chameleon.cpp: In function 'std::vector<std::pair<int, int> > {anonymous}::get_all_edges(std::vector<int>, int)':
chameleon.cpp:36:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     while(Query(reunion(a, {node})) < a.size() + 1){
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
chameleon.cpp:39:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         if(x + jump <= a.size() && query(reunion(pref(a, x + jump), {node})) == x + jump + 1)
      |            ~~~~~~~~~^~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:57:50: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |       if(query(reunion(independent_set[j], {i})) == independent_set[j].size() + 1) {
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chameleon.cpp:65:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for(int h = 0; h < edges.size(); h++)
      |                        ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...