#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
ostream& operator<<(ostream &out, string str) {
for(char c : str) out << c;
return out;
}
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
return out << "(" << p.ST << ", " << p.ND << ")";
}
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
out << "{";
for(auto it = a.begin(); it != a.end(); it = next(it))
out << (it != a.begin() ? ", " : "") << *it;
return out << "}";
}
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
cerr << a << ", ";
dump(x...);
}
#ifdef DEBUG
# define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
# define debug(...) false
#endif
template<class T> int size(T && a) { return (int) a.size(); }
using LL = long long;
using PII = pair<int, int>;
vector<vector<int>> jump;
vector<char> label;
vector<int> dep;
int get_ptr(int v, int q) {
if(q < size(jump[v]))
return jump[v][q];
return -1;
}
int add_vertex(char c, int p) {
label.emplace_back(c);
if(p != -1) dep.emplace_back(dep[p] + 1);
else dep.emplace_back(-1);
jump.emplace_back();
auto &j = jump.back();
while(p != -1) {
j.emplace_back(p);
p = get_ptr(p, size(j) - 1);
}
return size(label) - 1;
}
vector<int> pos;
void Init() {
pos.emplace_back(add_vertex(0, -1));
}
void TypeLetter(char L) {
int last = pos.back();
pos.emplace_back(add_vertex(L, last));
}
void UndoCommands(int U) {
int s = size(pos) - 1;
pos.emplace_back(pos[s - U]);
}
char GetLetter(int P) {
int q = 0, v = pos.back();
int k = dep[v] - P;
while(k) {
if(k % 2)
v = get_ptr(v, q);
k /= 2, q++;
}
return label[v];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
6 ms |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
640 KB |
Output is correct |
5 |
Correct |
6 ms |
512 KB |
Output is correct |
6 |
Correct |
7 ms |
768 KB |
Output is correct |
7 |
Correct |
6 ms |
640 KB |
Output is correct |
8 |
Correct |
6 ms |
640 KB |
Output is correct |
9 |
Correct |
7 ms |
640 KB |
Output is correct |
10 |
Correct |
6 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
896 ms |
100488 KB |
Output is correct |
2 |
Correct |
973 ms |
111728 KB |
Output is correct |
3 |
Correct |
602 ms |
78092 KB |
Output is correct |
4 |
Correct |
544 ms |
61960 KB |
Output is correct |
5 |
Correct |
638 ms |
95880 KB |
Output is correct |
6 |
Correct |
674 ms |
119020 KB |
Output is correct |
7 |
Correct |
519 ms |
58636 KB |
Output is correct |
8 |
Correct |
573 ms |
89284 KB |
Output is correct |
9 |
Correct |
919 ms |
124144 KB |
Output is correct |
10 |
Correct |
392 ms |
62088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
729 ms |
81032 KB |
Output is correct |
2 |
Correct |
737 ms |
70400 KB |
Output is correct |
3 |
Correct |
527 ms |
59004 KB |
Output is correct |
4 |
Correct |
497 ms |
46464 KB |
Output is correct |
5 |
Correct |
561 ms |
91736 KB |
Output is correct |
6 |
Correct |
541 ms |
76336 KB |
Output is correct |
7 |
Correct |
566 ms |
89356 KB |
Output is correct |
8 |
Correct |
714 ms |
43384 KB |
Output is correct |
9 |
Correct |
780 ms |
78960 KB |
Output is correct |
10 |
Correct |
378 ms |
61572 KB |
Output is correct |