Submission #76861

# Submission time Handle Problem Language Result Execution time Memory
76861 2018-09-18T18:42:44 Z FiloSanza Crayfish scrivener (IOI12_scrivener) C++14
0 / 100
854 ms 209332 KB
#include <bits/stdc++.h>

using namespace std;

struct Node{
	const int MAX_SIZE = 30;
	char val;
	int depth;
	Node* father;
	Node* kth;
	vector<Node*> figli;

	Node(char val, int depth) : val(val), depth(depth), father(nullptr), kth(nullptr){
		figli.resize(MAX_SIZE, nullptr);
	}
	Node(char val, int depth, Node* N, Node* kth) : val(val), depth(depth), father(N), kth(kth){
		figli.resize(MAX_SIZE, nullptr);
	}
};

struct Trie{
	Node *root = nullptr;
	vector<Node *> version;
	int curr = 0;
	//costruttore
	Trie(){
		root = new Node('\0', -1);
		version.push_back(root);
	}

	Node* getKth(int k){
		if(k == 0)
			return version[0];
		Node* node = version[curr];
		while(node->depth != k){
			node = (node->kth->depth >= k) ? node->kth : node->father;
		}
		return node;
	}
	//Devo aggiungere nell'ultima versione il carattere(New Node se non esiste) e aggiungere una versione
	void insert(char c){
		int val = c - 'a';
		int h = version[curr]->depth+1;
		//Non esiste, lo creo
		if(version[curr]->figli[val] == nullptr){
			Node* ancestor = getKth(h-(h&(-h)));
			version[curr]->figli[val] = new Node(c, h, version[curr], ancestor);
		}
		//aggiungo la nuova versione
		version.push_back(version[curr]->figli[val]);
		curr ++;
	}
	//Per tornare indietro di N versioni mi basta andare all'indice curr - k del vettore
	void goBack(int k){
		version.push_back(version[curr-k]);
		curr++;
	}

};

Trie t;

void Init() {}

void TypeLetter(char L) {
	t.insert(L);
}

void UndoCommands(int U) {
	t.goBack(U);
}

char GetLetter(int P) {
	return t.getKth(P)->val;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 484 KB Output is correct
2 Incorrect 2 ms 484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 872 KB Output is correct
2 Correct 4 ms 872 KB Output is correct
3 Correct 4 ms 876 KB Output is correct
4 Correct 6 ms 1384 KB Output is correct
5 Incorrect 4 ms 1384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 578 ms 186632 KB Output is correct
2 Correct 483 ms 209332 KB Output is correct
3 Correct 454 ms 209332 KB Output is correct
4 Correct 454 ms 209332 KB Output is correct
5 Incorrect 854 ms 209332 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 754 ms 209332 KB Output isn't correct
2 Halted 0 ms 0 KB -