Submission #1185026

#TimeUsernameProblemLanguageResultExecution timeMemory
1185026Gabp크레이피쉬 글쓰는 기계 (IOI12_scrivener)C++20
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;

const int m = 21;

struct Node {
    char c;
    int idx;
    Node *p[m];
    
    Node(char c, Node *par) : c(c) {
        if (par) {
            idx = par->idx + 1;
            p[0] = par;
            for (int i = 1; i < m; i++) {
                p[i] = p[i - 1]->p[i - 1];
            }
        } else {
            idx = -1;
            for (int i = 0; i < m; i++) p[i] = this;
        }
    }
};

int cnt = 0;
const int N = 1e6 + 5;
Node *memo[N];

void Init() {
    memo[0] = new Node('\0', nullptr);
}

void TypeLetter(char L) {
    memo[++cnt] = new Node(L, memo[cnt]);
}

void UndoCommands(int U) {
    memo[++cnt] = memo[cnt - U];
}

char GetLetter(int P) {
    int diff = memo[cnt]->idx - P;
    Node *curr = memo[cnt];
    for (int i = 0; i < m; i++) {
        if (diff & 1) curr = curr->p[i];
    }
    return curr->c;
}

int main() {
    Init();
    TypeLetter('a');
    TypeLetter('b');
    cout << GetLetter(1) << endl;
    TypeLetter('d');
    UndoCommands(2);
    UndoCommands(1);
    cout << GetLetter(2) << endl;
    TypeLetter('e');
    UndoCommands(1);
    UndoCommands(5);
    TypeLetter('c');
    cout << GetLetter(2) << endl;
    UndoCommands(2);
    cout << GetLetter(2) << endl;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccjquews.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccNx2pLX.o:scrivener.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status