Submission #215892

#TimeUsernameProblemLanguageResultExecution timeMemory
215892BTheroChameleon's Love (JOI20_chameleon)C++17
100 / 100
69 ms572 KiB
#define DBG 1 // chrono::system_clock::now().time_since_epoch().count() #include<bits/stdc++.h> #include "chameleon.h" //#include<ext/pb_ds/tree_policy.hpp> //#include<ext/pb_ds/assoc_container.hpp> #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define all(x) (x).begin(), (x).end() #define debug(x) if (DBG) cerr << #x << " = " << x << endl; using namespace std; //using namespace __gnu_pbds; typedef long long ll; typedef pair<int, int> pii; //template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; namespace { const int MAXN = 1005; vector<int> adj[MAXN]; int partner[MAXN], loves[MAXN], n; int col[MAXN]; void addEdge(int u, int v, bool check = 0) { if (check && Query({u, v}) != 1) { return; } adj[u].pb(v); adj[v].pb(u); } void dfs(int v) { for (int to : adj[v]) { if (col[to] == -1) { col[to] = 1 - col[v]; dfs(to); } else if (col[to] == col[v]) { assert(0); } } } } void Solve(int _n) { n = _n; for (int i = 1; i <= 2 * n; ++i) { for (int j = 1; j < i; ++j) { col[j] = -1; } vector<vector<int>> vec(2); for (int j = 1; j < i; ++j) { if (col[j] == -1) { col[j] = 0; dfs(j); } vec[col[j]].pb(j); } for (vector<int> v : vec) { vector<int> tmp = v; tmp.pb(i); while (Query(tmp) != tmp.size()) { int l = 0; int r = (int)v.size() - 1; int p = -1; while (l <= r) { int mid = (l + r) >> 1; tmp = {i}; for (int j = 0; j <= mid; ++j) { tmp.pb(v[j]); } if (Query(tmp) == tmp.size()) { l = mid + 1; } else { r = mid - 1; p = mid; } } addEdge(i, v[p], 1); tmp = vector<int>(v.begin() + p + 1, v.end()); v = tmp; tmp.pb(i); } } } for (int i = 1; i <= 2 * n; ++i) { assert(adj[i].size() == 1 || adj[i].size() == 3); if (adj[i].size() == 1) { partner[i] = adj[i][0]; continue; } while (Query({i, adj[i][0], adj[i][1]}) != 1) { rotate(adj[i].begin(), adj[i].begin() + 1, adj[i].end()); } loves[i] = adj[i][2]; } for (int i = 1; i <= 2 * n; ++i) { if (loves[adj[i][0]] == i) { partner[i] = adj[i][1]; } else { partner[i] = adj[i][0]; } } for (int i = 1; i <= 2 * n; ++i) { if (i < partner[i]) { Answer(i, partner[i]); } } }

Compilation message (stderr)

chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:75:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while (Query(tmp) != tmp.size()) {
                    ~~~~~~~~~~~^~~~~~~~~~~~~
chameleon.cpp:88:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     if (Query(tmp) == tmp.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...