Submission #107583

# Submission time Handle Problem Language Result Execution time Memory
107583 2019-04-25T08:33:19 Z ekrem Crayfish scrivener (IOI12_scrivener) C++
0 / 100
238 ms 117980 KB
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 1100005
using namespace std;

typedef long long ll;

struct node{
	int git[26], par[23], ne, der;
} x[N];

int n, m, k, yer[N], lg[N];

void Init(){
	for(int i = 5; i >= 1; i--){
		for(int j = (1<<i); j > (1<<(i - 1)); j--){
			lg[j] = i + 1;
			// cout << j << " " << i << endl;
		}
	}
	lg[0] = 1;
	lg[1] = 2;
}

void TypeLetter(char c){
	int node = yer[m];
	c -= 'a';
	if(x[node].git[c] != 0)
		yer[++m] = x[node].git[c];
	else{
		x[node].git[c] = ++k;
		x[k].par[0] = node;
		x[k].ne = c;
		x[k].der = x[node].der + 1;
		// cout << node << " ->" << k << endl;
		yer[++m] = k;
		for(int i = 1; i < lg[x[k].der] + 1; i++){
			if(x[k].par[i - 1] == 0)
				break;
			x[k].par[i] = x[x[k].par[i - 1]].par[i - 1];
		}
	}
}

void UndoCommands(int y){
	yer[m + 1] = yer[m - y];
	m++;
}

char GetLetter(int y){
	int node = yer[m];
	y = x[node].der - (y + 1);
	// cout << node << " " << y << " inci harfi bul, en son " << (char)(x[node].ne + 'a') << " var. " << x[node].der << " uzunlugunda" << endl;
	for(int i = lg[y] + 1; i >= 0; i--){
		if((1<<i) <= y){
			y -= (1<<i);
			node = x[node].par[i];
		}
	}
	// cout << node << endl;
	return x[node].ne + 'a';
}

// int main() {
// 	freopen("in.txt", "r", stdin);
// 	freopen("out.txt", "w", stdout);
// 	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;
// 	return 0;
// }

Compilation message

scrivener.cpp: In function 'void TypeLetter(char)':
scrivener.cpp:32:18: warning: array subscript has type 'char' [-Wchar-subscripts]
  if(x[node].git[c] != 0)
                  ^
scrivener.cpp:33:27: warning: array subscript has type 'char' [-Wchar-subscripts]
   yer[++m] = x[node].git[c];
                           ^
scrivener.cpp:35:16: warning: array subscript has type 'char' [-Wchar-subscripts]
   x[node].git[c] = ++k;
                ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 3 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Incorrect 2 ms 384 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 215 ms 117980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 238 ms 99844 KB Output isn't correct
2 Halted 0 ms 0 KB -