Submission #216055

#TimeUsernameProblemLanguageResultExecution timeMemory
216055_7_7_Chameleon's Love (JOI20_chameleon)C++14
100 / 100
408 ms22136 KiB
#include "chameleon.h" #include <bits/stdc++.h> //#define int long long //#pragma GCC optimize("Ofast") //#pragma comment(linker, "/stack:200000000") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4") #define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout); #define all(x) x.begin(), x.end() #define sz(s) (int)s.size() #define pb push_back #define ppb pop_back #define mp make_pair #define s second #define f first using namespace std; typedef pair < long long, long long > pll; typedef pair < int, int > pii; typedef unsigned long long ull; typedef vector < pii > vpii; typedef vector < int > vi; typedef long double ldb; typedef long long ll; typedef double db; const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 1e3 + 11; const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 333; const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9); const db eps = 1e-12, pi = 3.14159265359; const ll INF = 1e18; int l[N], n; vi v[2], g[N]; map < vi, int > was; bool used[N], used1[N]; int query (vi v) { sort(all(v)); if (was.count(v)) return was[v]; return was[v] = Query(v); } void ans (int x, int y) { assert(used[x] == used[y]); if (!used[x]) Answer(x, y); used[x] = used[y] = 1; } void dfs (int vv, int cc = 0) { v[cc].pb(vv); used1[vv] = 1; for (auto to : g[vv]) if (!used1[to]) dfs(to, cc ^ 1); } void f (int i) { while (1) { v[0].pb(i); if (query(v[0]) == sz(v[0])) break; v[0].ppb(); int l = 0, r = sz(v[0]) - 1, j = -1; while (l <= r) { int mid = (l + r) >> 1; vi tmp; for (int x = 0; x <= mid; ++x) tmp.pb(v[0][x]); tmp.pb(i); if (query(tmp) != sz(tmp)) { j = mid; r = mid - 1; } else l = mid + 1; } g[i].pb(v[0][j]); g[v[0][j]].pb(i); swap(v[0][j], v[0][sz(v[0]) - 1]); v[0].ppb(); } } void Solve(int nn) { n = nn; for (int i = 1; i <= n + n; ++i) { f(i); swap(v[0], v[1]); f(i); v[0].clear(); v[1].clear(); memset(used1, 0, sizeof(used1)); for (int j = 1; j <= i; ++j) if (!used1[j]) dfs(j); }/* for (auto x : v[0]) cerr << x << ' '; cerr << endl; for (auto x : v[1]) cerr << x << ' '; cerr << endl; for (int i = 1; i <= n + n; ++i) for (auto j : g[i]) cerr << i << ' ' << j << endl;*/ for (int i = 1; i <= n + n; ++i) if (!used[i]) { assert(sz(g[i]) == 1 || sz(g[i]) == 3); if (sz(g[i]) == 1) ans(i, g[i][0]); else { for (int j = 0; j < 2; ++j) { vi tmp; tmp.pb(i); for (int jj = 0; jj < 3; ++jj) if (jj != j) tmp.pb(g[i][jj]); if (query(tmp) == 1) { l[i] = g[i][j]; break; } } if (!l[i]) l[i] = g[i][2]; } } /* for (int i = 1; i <= n + n; ++i) cerr << l[i] << endl;*/ for (int i = 1; i <= n + n; ++i) if (!used[i]) { for (int j = 0; j < 3; ++j) if (g[i][j] == l[i]) { swap(g[i][j], g[i][2]); g[i].ppb(); break; } assert(sz(g[i]) == 2); if (l[g[i][0]] == i || used[g[i][0]]) ans(i, g[i][1]); else { assert(l[g[i][1]] == i || used[g[i][1]]); ans(i, g[i][0]); } } }
#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...