이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct Node{
const int MAX_SIZE = 30;
char val;
int depth;
Node* father;
vector<Node*> figli;
Node(char val, int depth) : val(val), depth(depth), father(nullptr){
figli.resize(MAX_SIZE, nullptr);
}
Node(char val, int depth, Node* N) : val(val), depth(depth), father(N){
figli.resize(MAX_SIZE, nullptr);
}
};
struct Trie{
Node *root = nullptr;
vector<Node *> version;
int curr = 0;
//costruttore
Trie(){
root = new Node('\0', -1);
version.push_back(root);
}
//Devo aggiungere nell'ultima versione il carattere(New Node se non esiste) e aggiungere una versione
void insert(char c){
int val = c - 'a';
//Non esiste, lo creo
if(version[curr]->figli[val] == nullptr){
version[curr]->figli[val] = new Node(c, version[curr]->depth+1, version[curr]);
}
//aggiungo la nuova versione
version.push_back(version[curr]->figli[val]);
curr ++;
}
//Per tornare indietro di N versioni mi basta andare all'indice curr - k del vettore
void goBack(int k){
version.push_back(version[curr-k]);
curr++;
}
char getKth(int k){
Node* node = version[curr];
while(node->depth != k){
node = node->father;
}
return node->val;
}
};
Trie t;
void Init() {}
void TypeLetter(char L) {
t.insert(L);
}
void UndoCommands(int U) {
t.goBack(U);
}
char GetLetter(int P) {
return t.getKth(P);
}
# | 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... |