제출 #75483

#제출 시각아이디문제언어결과실행 시간메모리
75483sevenkplus자동 인형 (IOI18_doll)C++14
63 / 100
126 ms11832 KiB
#include "doll.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> PII; #define fi first #define se second #define pb push_back #define mp make_pair #define pct __builtin_popcount #define INF 1000000007 vector<PII> ff(vector<int> a) { int n = (int) a.size(); int p = 1; while (p < n) p *= 2; vector<PII> s(p-1); vector<bool> t(p-1, 0); for (int i = 0; i < p/2-1; i ++) s[i] = mp(-(i*2+1 +1), -(i*2+2 +1)); for (int i = 0; i < p; i ++) { int x = 0; while (x < p-1) { if (t[x] == 1) { t[x] = 0; x = x*2+2; } else { t[x] = 1; x = x*2+1; } } int ne = -1; if (i >= p-n) ne = a[i-(p-n)]; if (x%2) s[(x-1)/2].fi = ne; else s[(x-1)/2].se = ne; } return s; } bool gg(int m, vector<int> a) { int n = a.size(); vector<int> sc(m + 1, -1); sc[0] = a[0]; vector<vector<int> > p(m+1); for (int i = 0; i < n; i ++) { int ne = 0; if (i != n-1) ne = a[i+1]; p[a[i]].pb(ne); if (p[a[i]].size() >= 5) return false; } vector<int> sx, sy; int nc = 0; for (int i = 1; i <= m; i ++) { if (p[i].empty()) { sc[i] = 0; continue; } if (p[i].size() == 1) { sc[i] = p[i][0]; continue; } vector<PII> v = ff(p[i]); sc[i] = -(nc+1); for (int j = 0; j < (int) v.size(); j ++) { int w = v[j].fi; if (w < 0) w -= nc; sx.pb(w); w = v[j].se; if (w < 0) w -= nc; sy.pb(w); } nc += (int) v.size(); } answer(sc, sx, sy); return true; } void create_circuit(int m, vector<int> a) { if (gg(m, a)) return; int n = a.size(); a.pb(0); vector<int> sc(m + 1, 0); sc[0] = a[0]; if (n == 1) { answer(sc, {}, {}); return; } for (int i = 1; i <= m; i ++) sc[i] = -1; int p = 1; while (p < n) p *= 2; vector<int> wx(p-1, INF); vector<int> wy(p-1, INF); vector<bool> t(p-1, 0); for (int i = 0; i < p/2-1; i ++) { wx[i] = -(i*2+1 +1); wy[i] = -(i*2+2 +1); } for (int i = 0; i < p; i ++) { int x = 0; while (x < p-1) { if (t[x] == 1) { t[x] = 0; x = x*2+2; } else { t[x] = 1; x = x*2+1; } } int ne = -1; if (i >= p-n) ne = a[i-(p-n)+1]; if (x%2) wx[(x-1)/2] = ne; else wy[(x-1)/2] = ne; } answer(sc, wx, wy); }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...