# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
483236 | syl123456 | Crayfish scrivener (IOI12_scrivener) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
vector<char> c;
vector<int> dep, ptr;
vector<vector<int>> pa, ch;
void Init() {
c.push_back('.');
dep.push_back(0);
ptr.push_back(0);
pa.emplace_back(20, 0);
ch.emplace_back(26, -1);
}
void TypeLetter(char L) {
int y = L - 'a', x = ptr.back();
if (ch[x][y] == -1) {
int i = ch[x][y] = c.size();
c.push_back(L);
dep.push_back(dep[x] + 1);
pa.emplace_back(20);
ch.emplace_back(26, -1);
pa[i][0] = x;
for (int j = 1; j < 20; ++j)
pa[i][j] = pa[pa[i][j - 1]][j - 1];
}
ptr.push_back(ch[t][x]);
}
void UndoCommands(int U) {
int i = ptr.size() - 1 - U;
ptr.push_back(ptr[i]);
}
char GetLetter(int P) {
++P;
int i = ptr.back();
for (int j = 19; ~j; --j)
if (dep[pa[i][j]] >= P)
i = pa[i][j];
return c[i];
}