Submission #104265

#TimeUsernameProblemLanguageResultExecution timeMemory
104265arman_ferdousCrayfish scrivener (IOI12_scrivener)C++14
100 / 100
713 ms86116 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e6+10; char c[N]; int lev[N]; int cur, freePtr; int p[20][N], state[N], ptr; void Init() { lev[0] = -1; memset(p,-1,sizeof p); c[0] = '?'; cur = 0; freePtr = 1; state[0] = cur; ptr = 0; } void TypeLetter(char L) { int idx = freePtr++; p[0][idx] = cur; c[idx] = L, lev[idx] = lev[cur] + 1; cur = idx; for(int j = 1; j < 20; ++j) if(p[j-1][cur] + 1) p[j][cur] = p[j-1][p[j-1][cur]]; state[++ptr] = cur; } void UndoCommands(int U) { state[ptr+1] = state[max(0, ptr - U)]; ptr++; cur = state[ptr]; } char GetLetter(int P) { int tmp = cur, need = lev[cur] - P; for(int j = 19; j >= 0; --j) if(need >= (1<<j)) { need -= (1<<j); tmp = p[j][tmp]; } return c[tmp]; }
#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...