제출 #1229943

#제출 시각아이디문제언어결과실행 시간메모리
1229943AMel0n크레이피쉬 글쓰는 기계 (IOI12_scrivener)C++20
0 / 100
681 ms242864 KiB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define FOR(i,N) for(ll i = 0; i < N; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second


// everything is 1-indexed

vector<int> cmd = {0};  // cmd[i] -> idx of cur node    after ith command
vector<int> len = {0};  // len[i] -> len of cur string  after ith command
vector<char> node = {' '}; // node value
vector<vector<int>> par(2e6, vector<int>(20)); // node parent (binary jumping)
int n = 1; // nodes created

void Init() {}

void TypeLetter(char ch) {
    len.push_back(len[cmd.back()] + 1);
    par[n][0] = cmd.back();
    cmd.push_back(n);
    node.push_back(ch);
    for(int j = 1; j < 20; j++) par[n][j] = par[par[n][j-1]][j-1];
    n++;
}

void UndoCommands(int k) {
    cmd.push_back(cmd[cmd.size()-1-k]);
}

char GetLetter(int k) {
    k = k - len[cmd.back()];
    int j = 19;
    int bru = cmd.back();
    while(j > -1) {
        if (pow(2, j) <= k) {
            bru = par[bru][j];
            k -= pow(2, j);
        }
        j--;
    }
    return node[bru];
}
#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...