Submission #885605

# Submission time Handle Problem Language Result Execution time Memory
885605 2023-12-10T09:52:03 Z Glauco Crayfish scrivener (IOI12_scrivener) C++17
34 / 100
528 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(3e6);

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[0] = curr;
  for(int i = 1; 1; i++){
    if(i-1 >= v[v[idx].hist[i-1]].hist.size()) break;
    
    if(i < v[idx].hist.size()) v[idx].hist[i] = v[v[idx].hist[i-1]].hist[i-1];
    else 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:49:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     if(i < v[idx].hist.size()) v[idx].hist[i] = v[v[idx].hist[i-1]].hist[i-1];
      |        ~~^~~~~~~~~~~~~~~~~~~~
scrivener.cpp: In function 'char GetLetter(int)':
scrivener.cpp:60:43: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   60 |     if((p & (1<<i)) && v[temp].str.size() > i) temp = v[temp].str[i];
      |                        ~~~~~~~~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 40 ms 188248 KB Output is correct
2 Correct 36 ms 188132 KB Output is correct
3 Correct 37 ms 188240 KB Output is correct
4 Correct 37 ms 188240 KB Output is correct
5 Correct 39 ms 188244 KB Output is correct
6 Correct 37 ms 188240 KB Output is correct
7 Correct 37 ms 188240 KB Output is correct
8 Correct 39 ms 188496 KB Output is correct
9 Correct 37 ms 188240 KB Output is correct
10 Correct 37 ms 188088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 188240 KB Output is correct
2 Correct 38 ms 188244 KB Output is correct
3 Correct 36 ms 188252 KB Output is correct
4 Correct 38 ms 188544 KB Output is correct
5 Correct 37 ms 188148 KB Output is correct
6 Correct 37 ms 188248 KB Output is correct
7 Correct 38 ms 188136 KB Output is correct
8 Correct 37 ms 188252 KB Output is correct
9 Correct 37 ms 188252 KB Output is correct
10 Correct 37 ms 188252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 188496 KB Output is correct
2 Correct 38 ms 188500 KB Output is correct
3 Correct 38 ms 188760 KB Output is correct
4 Correct 38 ms 188736 KB Output is correct
5 Correct 38 ms 188592 KB Output is correct
6 Correct 38 ms 188800 KB Output is correct
7 Correct 39 ms 189016 KB Output is correct
8 Correct 39 ms 188764 KB Output is correct
9 Correct 39 ms 188888 KB Output is correct
10 Correct 39 ms 188756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 458 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 528 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -