Submission #466448

#TimeUsernameProblemLanguageResultExecution timeMemory
466448prvocisloChameleon's Love (JOI20_chameleon)C++17
100 / 100
76 ms560 KiB
#include "chameleon.h" #include <vector> #include <iostream> using namespace std; const int maxn = 505; vector<int> g[maxn * 2]; vector<pair<int, int>> v; bool vis[maxn * 2]; bool query(int x, vector<int> a) // vrati true ak mame menej farieb ako chameleonov { a.push_back(x); return Query(a) < a.size(); } void dfs(int u, int c, vector<vector<int> >& k) { k[c].push_back(u), vis[u] = true; for (int v : g[u]) if (!vis[v]) dfs(v, c ^ 1, k); } void rmv(int a, int b) { for (int i = 0; i < g[a].size(); i++) if (g[a][i] == b) { g[a].erase(g[a].begin() + i); break; } } void Solve(int n) { for (int i = 2; i <= 2 * n; i++) { vector<vector<int> > k(2); for (int j = 0; j <= i; j++) vis[j] = false; for (int j = 1; j < i; j++) if (!vis[j]) dfs(j, 0, k); for (int j = 0; j < 2; j++) while (k[j].size() && query(i, k[j])) { int lo = 1, hi = k[j].size(); while (lo < hi) { int mi = (lo + hi) >> 1; if (query(i, vector<int>(k[j].begin(), k[j].begin() + mi))) hi = mi; else lo = mi + 1; } g[i].push_back(k[j][lo - 1]), g[k[j][lo - 1]].push_back(i); k[j] = vector<int>(k[j].begin() + lo, k[j].end()); } } for (int i = 1; i <= 2 * n; i++) if (g[i].size() == 3) { for (int j = 0; j < 3; j++) for (int k = 0; k < j; k++) { if (Query({ i, g[i][j], g[i][k] }) == 1) v.push_back({ i, g[i][3 ^ j ^ k] }); } } for (const pair<int, int>& i : v) { rmv(i.first, i.second); rmv(i.second, i.first); } for (int i = 1; i <= 2 * n; i++) if (g[i][0] > i) { Answer(i, g[i][0]); } }

Compilation message (stderr)

chameleon.cpp: In function 'bool query(int, std::vector<int>)':
chameleon.cpp:13:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  return Query(a) < a.size();
      |         ~~~~~~~~~^~~~~~~~~~
chameleon.cpp: In function 'void rmv(int, int)':
chameleon.cpp:22:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  for (int i = 0; i < g[a].size(); i++) if (g[a][i] == b)
      |                  ~~^~~~~~~~~~~~~
#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...