제출 #104384

#제출 시각아이디문제언어결과실행 시간메모리
104384dfistric크레이피쉬 글쓰는 기계 (IOI12_scrivener)C++14
34 / 100
1064 ms162860 KiB
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) FOR(i, 0, n)

using namespace std;

struct node {
    node* ch[30];
    node* par;
    char c;

    node(node* n, char cc) {
        REP(i, 30) ch[i] = 0;
        par = n, c = cc;
    }
};
node* root;

vector <node*> ve;
int flag;
string s;

void Init() {
    root = new node(NULL, '.');
    ve.push_back(root);

    return;
}

void TypeLetter(char L) {
    flag = 1;

    int x = (L - 'a');   
    if (!root->ch[x]) root->ch[x] = new node(root, L);
    root = root->ch[x];
    ve.push_back(root);

    return;
}

void UndoCommands(int U) {
    flag = 1;

    root = ve[ve.size() - 1 - U];
    ve.push_back(root);

    return;
}

char GetLetter(int P) {
    if (flag) {
        s = "";
        node* curr = root;
        while (curr) {
            s = s + curr->c;
            curr = curr->par;
        }
        reverse(s.begin(), s.end());
        flag = 0;
    }
    return s[P + 1];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...