Submission #574228

#TimeUsernameProblemLanguageResultExecution timeMemory
574228MadokaMagicaFanMechanical Doll (IOI18_doll)C++14
53 / 100
115 ms18456 KiB
#include "bits/stdc++.h" using namespace std; using ll = long long; const ll inf = 1e9; const int md1 = 1e9+7; const int md2 = 998244353; #define sz(v) ((int)v.size()) #define pb push_back #define pry cout << "YES\n" #define prn cout << "NO\n" #define endl '\n' #define fst first #define scn second /* #define ONPC */ const int M = 1e5; vector<int> v[M+5], x, y, c; void answer(vector<int> C, vector<int> X, vector<int> Y); int news() { x.pb(0); y.pb(0); return sz(x); } int dfs(int i, int s, int k, int ind) { if (k == x[ind-1]) { if (s >= sz(v[i])-1) { if (s == (1<<x[ind-1])-1) return v[i][sz(v[i])-1]; else return -ind; } return v[i][s]; } int _x = dfs(i,s,k+1,ind); int _y = dfs(i,s+(1<<k),k+1,ind); if (_x == _y) return _x; int index = news(); x[index-1] = _x; y[index-1] = _y; return -index; } int donode(int i) { if (sz(v[i]) == 1) return v[i][0]; int l = 31 - __builtin_clz(sz(v[i])); if (sz(v[i]) != (1<<l)) ++l; int ind = news(); x[ind-1] = l; int _x = dfs(i,0,1,ind); int _y = dfs(i,1,1,ind); x[ind-1] = _x; y[ind-1] = _y; return -ind; } void create_circuit(int m, vector<int> a) { int n = sz(a); for (int i = 0; i < n-1; ++i) v[a[i]].pb(a[i+1]); v[a[n-1]].pb(0); v[0].pb(a[0]); for (int i = 0; i < m+1; ++i) { if (sz(v[i]) == 0) { c.pb(1); continue; } c.pb(donode(i)); } answer(c,x,y); return; } #ifdef ONPC void answer(vector<int> C, vector<int> X, vector<int> Y) { vector<int> ans; vector<bool> state(sz(X),0); int tg = C[0]; while (tg) { if (tg >= 0) { ans.pb(tg); tg = C[tg]; } else { int index = -tg-1; if (state[index]==0) tg = X[index]; else tg = Y[index]; state[index] = !state[index]; } } for (int i = 0; i < sz(X); ++i) { if (state[i]) { cout << "Error\n"; return; } } cout << sz(ans) << endl; for (int i = 0; i < sz(ans); ++i) { cout << ans[i] << ' '; } cout << endl; return; } void solve() { int n, m; cin >> m; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; cout << m << ' '; create_circuit(m, a); } int32_t main(int argc, char **argv) { if (argc >= 2) { freopen(argv[1], "r", stdin); } else ios_base::sync_with_stdio(0);cin.tie(0); int t = 1; /* cin >> t; */ while(t--) solve(); } #endif
#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...