# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
126332 | groeneprof | Crayfish scrivener (IOI12_scrivener) | C++14 | 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.
#include <bits/stdc++.h>
#define P(x) do {if(debug) cout << x << endl;} while(false)
#define H(x) P(#x << ": " << x)
#define FR(i, a, b) for(int i = (a); i < (b); ++i)
#define F(i, n) FR(i, 0, n)
using namespace std;
const bool debug = 0 ;
const int inf = 1e9;
const int N = 1000005;
//int ind[N];
char parent[N];
int depth[N];
int memo[N][23];
bool check[N][23];
int cur;
/*int root(int a){
if(a==ind[a]){
return a;
}
return ind[a] = root(ind[a]);
}*/
void print(){
if(debug){
//cout<<"ind: ";
//F(i, cur+1) cout<<ind[i]<<" ";
cout<<"\nparent: ";
F(i, cur+1) cout<<parent[i]<<" ";
cout<<"\ndepth: ";
F(i, cur+1) cout<<depth[i]<<" ";
cout<<"\nmemo: ";
F(i, cur+1) cout<<memo[i][0]<<" ";
}
}
int f(int i, int h){
if(check[i][h]){
return memo[i][h];
}
check[i][h] = true;
return memo[i][h] = f(f(i,h-1) , h-1);
}
void Init() {
//ind[0] = 0;
parent[0] = '\\';
depth[0] = 0;
P("I");
//memo.resize(N, vector<int> (23, -1));
memo[0][0] = 0;
check[0][0] = true;
P("II");
cur = 0;
}
void TypeLetter(char L) {
H(L);
int n = cur+1;
//ind[n] = n;
parent[n]=L;
memo[n][0] = cur;
check[n][0] = true;
depth[n] = depth[cur]+1;
//cout<<endl;
cur = n;
}
void UndoCommands(int U) {
H(U);
parent[cur+1] = parent[cur-U];
depth[cur+1] = depth[cur-U];
memo[cur+1] = memo[cur-U];
check[cur+1] = memo[cur-U];
cur++;
}
char GetLetter(int P) {
H(P);
print();
int res = cur;
for(int h = 22; h>=0; h--){
if(depth[f(res, h)]>P) res = f(res, h);
}
return parent[res];
}