제출 #416979

#제출 시각아이디문제언어결과실행 시간메모리
416979Collypso크레이피쉬 글쓰는 기계 (IOI12_scrivener)C++17
34 / 100
1083 ms57856 KiB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#define F first
#define S second
//#define endl '\n'
//#define int long long

#define inbuf_len 1 << 16
#define outbuf_len 1 << 16

using namespace std;

struct node
{
    char val;
    int parent, h;
    vt<int> children;

    node() { h = 0; }

    node(char val_, int parent_, int h_) { val = val_, parent = parent_, h = h_; }
};

vt<node> trie;
vt<int> commands;

void Init()
{
    trie.pb({});
    commands.pb(0);
}

void TypeLetter(char L)
{
    int i = *commands.rbegin();
    trie[i].children.pb(sz(trie));
    trie.pb({L, i, trie[i].h + 1});
    commands.pb(sz(trie) - 1);
    //for(int i : commands) cout << i << " ";
    //cout << endl;
}

void UndoCommands(int U)
{
    int n = sz(commands);
    commands.pb(commands[n - U - 1]);
    //for(int i : commands) cout << i << " ";
    //cout << endl;
}

char GetLetter(int P)
{
    int v = *commands.rbegin();
    int d = trie[v].h - P - 1;
    while(d--) v = trie[v].parent;
    return trie[v].val;
}
#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...