Submission #885601

# Submission time Handle Problem Language Result Execution time Memory
885601 2023-12-10T09:46:39 Z Glauco Crayfish scrivener (IOI12_scrivener) C++17
0 / 100
54 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;

int idx = 1, curr = 0;
struct node{
  char c;
  vector<int> hist, str;
  int size;
};
vector<node> v(2e7);

void Init(){
  v[0].c = '0';
  v[0].size = 0;
}

void TypeLetter(char l){
  v[idx].c = l;
  v[idx].size = v[curr].size+1;
  
  v[idx].str.push_back(curr);
  for(int i = 1; 1; i++){
    if(i-1 >= v[v[idx].str[i-1]].str.size()) break;
    v[idx].str.push_back(v[v[idx].str[i-1]].str[i-1]);
  }

  v[idx].hist.push_back(curr);
  for(int i = 1; 1; i++){
    if(i-1 >= v[v[idx].hist[i-1]].hist.size()) break;
    v[idx].hist.push_back(v[v[idx].hist[i-1]].hist[i-1]);
  }

  curr = idx;
  idx++;
}

void UndoCommands(int u){
  int l = log2(idx)+3;
  int temp = curr;
  for(int i = l; i >= 0; i--){
    if((u & (1<<i)) && v[temp].hist.size() > i) temp = v[temp].hist[i];
  }

  v[idx] = v[temp];
  v[idx].hist.clear(); v[idx].hist.push_back(curr);
  for(int i = 1; 1; i++){
    if(i-1 >= v[v[idx].hist[i-1]].hist.size()) break;
    v[idx].hist.push_back(v[v[idx].hist[i-1]].hist[i-1]);
  }

  curr = idx;
  idx++;
}

char GetLetter(int p){
  int l = log2(idx)+3; p = v[curr].size-p-1; int temp = curr;
  for(int i = l; i >= 0; i--){
    if((p & (1<<i)) && v[temp].str.size() > i) temp = v[temp].str[i];
  }

  return v[temp].c;
}

Compilation message

scrivener.cpp: In function 'void TypeLetter(char)':
scrivener.cpp:23:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     if(i-1 >= v[v[idx].str[i-1]].str.size()) break;
      |        ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
scrivener.cpp:29:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     if(i-1 >= v[v[idx].hist[i-1]].hist.size()) break;
      |        ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
scrivener.cpp: In function 'void UndoCommands(int)':
scrivener.cpp:41:44: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   41 |     if((u & (1<<i)) && v[temp].hist.size() > i) temp = v[temp].hist[i];
      |                        ~~~~~~~~~~~~~~~~~~~~^~~
scrivener.cpp:47:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     if(i-1 >= v[v[idx].hist[i-1]].hist.size()) break;
      |        ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
scrivener.cpp: In function 'char GetLetter(int)':
scrivener.cpp:58:43: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   58 |     if((p & (1<<i)) && v[temp].str.size() > i) temp = v[temp].str[i];
      |                        ~~~~~~~~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Runtime error 54 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 38 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 40 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 40 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 37 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -