Submission #910045

#TimeUsernameProblemLanguageResultExecution timeMemory
910045MackerCrayfish scrivener (IOI12_scrivener)C++17
Compilation error
0 ms0 KiB
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>

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

void Init();
void TypeLetter(char L);
void UndoCommands(int U);
char GetLetter(int P);

int main() {
  Init();

  int cmd_num;
  auto tmp = scanf("%d", &cmd_num);
  assert(tmp == 1);

  int i;
  for (i = 0; i < cmd_num; i++) {
    char cmd;
    tmp = scanf(" %c", &cmd);
    assert(tmp == 1);
    if (cmd == 'T') {
      char letter;
      tmp = scanf(" %c", &letter);
      assert(tmp == 1);
      TypeLetter(letter);
    }
    else if (cmd == 'U') {
      int number;
      tmp = scanf("%d", &number);
      assert(tmp == 1);
      UndoCommands(number);
    }
    else if (cmd == 'P') {
      int index;
      char letter;
      tmp = scanf("%d", &index);
      assert(tmp == 1);
      letter = GetLetter(index);
      printf("%c\n", letter);
    }
  }
  
  puts("Let's test for cheating!!");

  return 0;

}

#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;
};
typedef node* pnode;

pnode cur;
vector<pnode> undo;

void Init() {
    cur = new node();
    cur->len = -1;
    undo.push_back(cur);
}

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->c = L;
    tmp->len = cur->len + 1;
    cur = tmp;
    undo.push_back(cur);
}

void UndoCommands(int U) {
    pnode tmp = undo[undo.size() - U - 1];
    cur = tmp;
    undo.push_back(cur);
}

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;
}

Compilation message (stderr)

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