Submission #402975

#TimeUsernameProblemLanguageResultExecution timeMemory
402975Charis02Crayfish scrivener (IOI12_scrivener)C++14
34 / 100
1094 ms14664 KiB
#include<iostream> #define MAX_N 1000004 using namespace std; struct node{ int par; int sqpar; int len; char c; }; node trie[MAX_N]; int sz; const int sqrt = 2000; void init_node(int cur,int par,char c) { trie[cur].par = par; trie[cur].c = c; trie[cur].len = trie[par].len+1; if(trie[cur].len%sqrt == 0) trie[cur].sqpar = par; else trie[cur].sqpar = trie[par].sqpar; return; } int get_ancestor(int cur,int x) { while(trie[trie[cur].sqpar].len >= x) cur = trie[cur].sqpar; while(trie[cur].len > x) cur = trie[cur].par; return cur; } void Init() { init_node(0,0,'-'); trie[0].len = 0; sz = 1; return; } void TypeLetter(char L) { init_node(sz,sz-1,L); sz++; return; } void UndoCommands(int U) { trie[sz] = trie[sz-U-1]; sz++; return; } char GetLetter(int P) { // cout << "here " << P << " " << sz-1 << " " << trie[sz-1].len << " " << get_ancestor(sz-1,trie[sz-1].len-P-1) << endl; return trie[get_ancestor(sz-1,P+1)].c; }
#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...