이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define MAXLG 20
struct Node {
int depth;
char ch;
Node* ancestors[MAXLG + 3];
Node(int depth_, char ch_, Node* parent = NULL) {
depth = depth_;
ch = ch_;
for (int lg = 0; lg <= MAXLG; lg++) {
ancestors[lg] = (parent == NULL ? NULL : parent->getKthParent((1 << lg) - 1));
}
}
Node* getKthParent(int k) {
Node* current = this;
for (int lg = 0; lg <= MAXLG && current != NULL; lg++) {
if (k & (1 << lg)) {
current = current->ancestors[lg];
}
}
return current;
}
};
Node* root = new Node(0, '.');
Node* currentNode = root;
vector<Node*> positions;
void Init() {
positions.push_back(root);
}
void TypeLetter(char L) {
Node* newNode = new Node(currentNode->depth + 1, L, currentNode);
positions.push_back(newNode);
currentNode = newNode;
}
void UndoCommands(int U) {
Node* node = positions[positions.size() - 1 - U];
positions.push_back(node);
currentNode = node;
}
char GetLetter(int P) {
return currentNode->getKthParent(currentNode->depth - 1 - P)->ch;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |