답안 #130251

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
130251 2019-07-14T11:50:39 Z khulegub 크레이피쉬 글쓰는 기계 (IOI12_scrivener) C++14
34 / 100
138 ms 35176 KB
#include <bits/stdc++.h>
#define pb push_back
#define xx first
#define yy second
#define mp make_pair
using namespace std;


/*

#############################################
# x X x _ P u $ $ y S l a y e r 6 9 _ x X x #
#############################################

*/

/*
Check array size
Check IO
*/

int curr;
vector<pair<char, int> > s; //storing chars and ranks
// vector<int> node_par; //storing each node's origin
int node_par[100005][20]; //nodes parents
int par[100005][20]; //cmds parents
// vector<int> node_par[20];
// // vector<int> par; //storing each cmd's origin
// vector<int> par[20]; //bin uplifting
vector<int> pos; //storing each cmd's position in "s"
void Init() {
	s.pb(mp('#', 0));
	curr = 0; //current cmd is 0
	pos.pb(0); //cmd 0 s position of node is 0
	node_par[0][0] = 0;
	par[0][0] = 0;
	// node_par.pb(0);
	// par.pb(0); //cmd zero came from zero lol
}
void TypeLetter(char L) {
	par[curr + 1][0] = curr; //2 ^ 0 th parent
	for (int i = 1; i <= 20; i++){
		par[curr + 1][i] = par[ par[curr + 1][i - 1] ][i - 1];
	}

	s.pb(mp(L, s[ pos[curr] ].yy + 1)); //typing letter means new node
	int node_curr = s.size() - 1;
	node_par[node_curr][0] = pos[curr];
	for (int i = 1; i <= 20; i++){
		node_par[node_curr][i] = node_par[ node_par[node_curr][i - 1] ][i - 1];
	}
	pos.pb(s.size() - 1);
	curr++;
}
void UndoCommands(int U) {
	int origin = curr;
	// need to uplift U times
	for (int i = 0; i <= 20; i++){ // decompose U into binary
		if ( (U & (1 << i)) ){
			origin = par[origin][i];
		}
	}
	par[curr + 1][0] = curr; //2 ^ 0 th parent
	for (int i = 1; i <= 20; i++){
		par[curr + 1][i] = par[ par[curr + 1][i - 1] ][i - 1];
	}
	curr++;
	pos.pb(pos[origin]);
}
char GetLetter(int P) {
	P++;
	int tmp = pos[curr];
	int j = s[tmp].yy - P;
	for (int i = 0; i <= 20; i++ ){
		if ( (j & (1 << i))){
			tmp = node_par[tmp][i];
		}
	}
	return s[tmp].xx;
}


// int main(){ //driver-chan
// 	Init();
// 	TypeLetter('a');
// 	cout << GetLetter(0);
// 	TypeLetter('b');
// 	cout << GetLetter(0);
// 	cout << GetLetter(1);
// 	UndoCommands(1);
// 	cout << GetLetter(0);
// 	TypeLetter('c');
// 	cout << GetLetter(1);
// 	// for (auto c : s){
// 	// 	cout << c.yy ;
// 	// }
// 	// cout << s.xx;
// }



/*
Atsaa hiiged bgan??
*/

Compilation message

scrivener.cpp: In function 'void TypeLetter(char)':
scrivener.cpp:43:20: warning: iteration 19 invokes undefined behavior [-Waggressive-loop-optimizations]
   par[curr + 1][i] = par[ par[curr + 1][i - 1] ][i - 1];
   ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
scrivener.cpp:42:20: note: within this loop
  for (int i = 1; i <= 20; i++){
                  ~~^~~~~
scrivener.cpp:50:26: warning: iteration 19 invokes undefined behavior [-Waggressive-loop-optimizations]
   node_par[node_curr][i] = node_par[ node_par[node_curr][i - 1] ][i - 1];
   ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
scrivener.cpp:49:20: note: within this loop
  for (int i = 1; i <= 20; i++){
                  ~~^~~~~
scrivener.cpp: In function 'void UndoCommands(int)':
scrivener.cpp:65:20: warning: iteration 19 invokes undefined behavior [-Waggressive-loop-optimizations]
   par[curr + 1][i] = par[ par[curr + 1][i - 1] ][i - 1];
   ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
scrivener.cpp:64:20: note: within this loop
  for (int i = 1; i <= 20; i++){
                  ~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 4 ms 760 KB Output is correct
3 Correct 4 ms 888 KB Output is correct
4 Correct 4 ms 1016 KB Output is correct
5 Correct 4 ms 776 KB Output is correct
6 Correct 4 ms 1016 KB Output is correct
7 Correct 5 ms 1016 KB Output is correct
8 Correct 4 ms 1016 KB Output is correct
9 Correct 5 ms 1016 KB Output is correct
10 Correct 4 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 112 ms 34936 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 138 ms 35176 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -