Submission #218310

#TimeUsernameProblemLanguageResultExecution timeMemory
218310edsaMechanical Doll (IOI18_doll)C++14
53 / 100
123 ms20524 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using vi = vector<int>; using vll = vector<ll>; using vii = vector<ii>; const ll MOD = 998244353; const int INF = 1e9+9; const int MAXN = 200005; #include "doll.h" int sm[2*MAXN], add[2*MAXN]; vi gr[MAXN]; vi C, X, Y; void create_circuit(int M, vector<int> A) { for (int i = 1; i < (int) A.size(); ++i) { gr[A[i-1]].push_back(A[i]); } gr[A.back()].push_back(0); C.resize(M+1); C[0] = A[0]; for (int i = 1; i <= M; ++i) { if (gr[i].empty()) { C[i] = 0; continue; } if (gr[i].size() == 1) { C[i] = gr[i][0]; continue; } int logg = 0; while ((1<<logg) < (int)gr[i].size()) logg++; // cerr << i << ": " << logg << endl; int fSw = X.size(); // first new switch X.resize((int) X.size()+(1<<logg)-1); Y.resize((int) Y.size()+(1<<logg)-1); C[i] = -fSw-1; gr[i].insert(gr[i].begin(), (1<<logg)-(int)gr[i].size(), -fSw-1); sm[1] = 0; add[1] = 1; int n = 1<<(logg-1); --fSw; for (int j = 1; j < n; ++j) { X[fSw+j] = -fSw-(j<<1)-1; Y[fSw+j] = -fSw-(j<<1|1)-1; sm[j<<1] = sm[j]; sm[j<<1|1] = sm[j]+add[j]; add[j<<1] = add[j<<1|1] = add[j]<<1; } for (int j = 0; j < n; ++j) { // cerr << j << ": " << add[n+j] << " " << sm[n+j] << endl; X[n+fSw+j] = gr[i][sm[n+j]]; Y[n+fSw+j] = gr[i][sm[n+j]+add[n+j]]; } } // for (int i = 0; i <= M; ++i) { // cerr << C[i] << ' '; // } // cerr << endl; // for (int i = 0; i < (int) X.size(); ++i) { // cerr << X[i] << ' ' << Y[i] << endl; // } answer(C, X, Y); }
#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...