#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;
FR(i, 1, 23){
memo[n][i] = memo[memo[n][i-1]][i-1];
//check[n][i] = true;
}
//cout<<endl;
cur = n;
}
void UndoCommands(int U) {
H(U);
parent[cur+1] = parent[cur-U];
depth[cur+1] = depth[cur-U];
F(i, 23){
memo[cur+1][i] = memo[cur-U][i];
//check[cur+1][i] = true;
}
cur++;
}
char GetLetter(int P) {
H(P);
print();
int res = cur;
for(int h = 22; h>=0; h--){
if(depth[memo[res][h]]>P) res = memo[res][h];
}
return parent[res];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
248 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
4 ms |
632 KB |
Output is correct |
3 |
Correct |
4 ms |
760 KB |
Output is correct |
4 |
Correct |
3 ms |
760 KB |
Output is correct |
5 |
Correct |
4 ms |
632 KB |
Output is correct |
6 |
Correct |
3 ms |
760 KB |
Output is correct |
7 |
Correct |
4 ms |
760 KB |
Output is correct |
8 |
Correct |
3 ms |
760 KB |
Output is correct |
9 |
Correct |
3 ms |
760 KB |
Output is correct |
10 |
Correct |
3 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
541 ms |
68384 KB |
Output is correct |
2 |
Correct |
630 ms |
83568 KB |
Output is correct |
3 |
Correct |
430 ms |
82808 KB |
Output is correct |
4 |
Correct |
449 ms |
86996 KB |
Output is correct |
5 |
Correct |
588 ms |
76536 KB |
Output is correct |
6 |
Correct |
548 ms |
90488 KB |
Output is correct |
7 |
Correct |
622 ms |
77344 KB |
Output is correct |
8 |
Correct |
639 ms |
87344 KB |
Output is correct |
9 |
Correct |
720 ms |
83960 KB |
Output is correct |
10 |
Correct |
276 ms |
94328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
775 ms |
62796 KB |
Output is correct |
2 |
Correct |
734 ms |
54140 KB |
Output is correct |
3 |
Correct |
433 ms |
68856 KB |
Output is correct |
4 |
Correct |
479 ms |
59720 KB |
Output is correct |
5 |
Correct |
550 ms |
80120 KB |
Output is correct |
6 |
Correct |
600 ms |
82936 KB |
Output is correct |
7 |
Correct |
571 ms |
82936 KB |
Output is correct |
8 |
Correct |
732 ms |
69752 KB |
Output is correct |
9 |
Correct |
883 ms |
72440 KB |
Output is correct |
10 |
Correct |
279 ms |
97288 KB |
Output is correct |