Submission #213316

#TimeUsernameProblemLanguageResultExecution timeMemory
213316popovicirobertChameleon's Love (JOI20_chameleon)C++14
100 / 100
89 ms888 KiB
#include "chameleon.h" #include <bits/stdc++.h> using namespace std; const int MAXN = 1000; static vector<int> g[MAXN + 1]; static vector<int> side[2]; static bool vis[MAXN + 1]; void dfs(int nod, int col) { if(vis[nod]) return ; vis[nod] = 1; side[col].push_back(nod); for(auto it : g[nod]) { dfs(it, col ^ 1); } } void Solve(int n) { vector<set<int>> all(2 * n + 1); for(int i = 1; i <= 2 * n; i++) { for(int t = 0; t < 2; t++) { int x = -1, sz = side[t].size(); while(x < sz && g[i].size() < 3) { vector<int> cur; cur.push_back(i); for(int j = x + 1; j < sz; j++) { cur.push_back(side[t][j]); } if(Query(cur) == cur.size()) { break; } int y = x; for(int step = 1 << 9; step; step >>= 1) { if(y + step < sz) { vector<int> cur; cur.push_back(i); for(int j = x + 1; j <= y + step; j++) { cur.push_back(side[t][j]); } if(Query(cur) == cur.size()) { y += step; } } } y++; if(y < sz) { all[i].insert(side[t][y]); all[side[t][y]].insert(i); g[i].push_back(side[t][y]); g[side[t][y]].push_back(i); } x = y; } side[t].clear(); } fill(vis, vis + i + 1, 0); for(int j = 1; j <= i; j++) { dfs(j, 0); } } for(int i = 1; i <= 2 * n; i++) { g[i].clear(); } for(int i = 1; i <= 2 * n; i++) { vector<int> cur; for(auto it : all[i]) { cur.push_back(it); } int j; if(cur.size() == 3) { if(Query({i, cur[0], cur[1]}) == 1) { j = cur[2]; } else if(Query({i, cur[1], cur[2]}) == 1) { j = cur[0]; } else { j = cur[1]; } g[i].push_back(j); g[j].push_back(i); } } for(int i = 1; i <= 2 * n; i++) { for(auto it : g[i]) { if(all[i].count(it)) { all[i].erase(it); } } assert(all[i].size() == 1); if(*all[i].begin() > i) { Answer(i, *all[i].begin()); } } }

Compilation message (stderr)

chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:32:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if(Query(cur) == cur.size()) {
                    ~~~~~~~~~~~^~~~~~~~~~~~~
chameleon.cpp:43:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                         if(Query(cur) == cur.size()) {
                            ~~~~~~~~~~~^~~~~~~~~~~~~
#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...