제출 #910044

#제출 시각아이디문제언어결과실행 시간메모리
910044Macker크레이피쉬 글쓰는 기계 (IOI12_scrivener)C++17
12 / 100
392 ms262144 KiB
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")

struct node {
    char c;
    array<node*, 22> par;
    int len;
    vector<array<pair<node*, int>, 22>> undo;
};
typedef node* pnode;

pnode root;
pnode cur;

void Init() {
    root = new node();
    root->len = -1;
    cur = root;
}

void TypeLetter(char L) {
    pnode tmp = new node();
    tmp->par[0] = cur;
    for (int i = 1; i < 22; i++) {
        if(tmp->par[i - 1] == NULL) break;
        tmp->par[i] = tmp->par[i - 1]->par[i - 1];
    }
    tmp->undo.push_back({});
    tmp->undo.back()[0] = {cur, cur->undo.size() - 1};
    for (int i = 1; i < 22; i++) tmp->undo.back()[i].second = -1;
    
    for (int i = 1; i < 22; i++) {
        if(tmp->undo.back()[i - 1].second == -1) break;
        int b = tmp->undo.back()[i - 1].second;
        tmp->undo.back()[i] = tmp->undo.back()[i - 1].first->undo[b][i - 1];
    }
    tmp->c = L;
    tmp->len = cur->len + 1;
    cur = tmp;
}

void UndoCommands(int U) {
    pnode tmp = cur;
    int b = tmp->undo.size() - 1;
    for (int i = 0; i < 22; i++) {
        if(U & (1 << i)){
            int tb = tmp->undo[b][i].second;
            tmp = tmp->undo[b][i].first;
            b = tb;
        }    
    }
    tmp->undo.push_back({});
    tmp->undo.back()[0] = {cur, cur->undo.size() - 1};
    for (int i = 1; i < 22; i++) tmp->undo.back()[i].second = -1;
    
    for (int i = 1; i < 22; i++) {
        if(tmp->undo.back()[i - 1].second == -1) break;
        int b = tmp->undo.back()[i - 1].second;
        tmp->undo.back()[i] = tmp->undo.back()[i - 1].first->undo[b][i - 1];
    }
    cur = tmp;
}

char GetLetter(int P) {
    pnode tmp = cur;
    int x = tmp->len - P;
    for (int i = 0; i < 22; i++) {
        if(x & (1 << i)){
            tmp = tmp->par[i];
        }
    }
    return tmp->c;
}
#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...