제출 #49982

#제출 시각아이디문제언어결과실행 시간메모리
49982Mamnoon_Siam크레이피쉬 글쓰는 기계 (IOI12_scrivener)C++17
100 / 100
746 ms185984 KiB
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;

#define debug(s) cout<< #s <<" = "<< s <<endl
#define all(v) (v).begin(), (v).end()
#define KeepUnique(v) (v).erase( unique(all(v)), v.end() )
#define MEMSET(a,val) memset(a, val, sizeof a)
#define PB push_back
#define endl '\n'

inline int myrand(int l, int r) {
	int ret = rand(); ret <<= 15; ret ^= rand();
	if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
	return ret;
}

template <typename F, typename S>
ostream& operator << (ostream& os, const pair< F, S>& p) {
    return os<<"(" <<p.first<<", "<<p.second<<")"; }

typedef pair<int, int> ii;
template<typename T> using min_pq =
	priority_queue<T, vector<T>, greater<T> >;

//int dx[] = {-1, +0, +1, +0};
//int dy[] = {+0, +1, +0, -1};

struct node {
	int h, to[26], par;
	char wot;
	node() {
		h = par = 0;
		MEMSET(to, 0);
	}
	node(int p, int H, char w0t) {
		h = H, par = p, wot = w0t;
		MEMSET(to, 0);
	}
};

deque<node> t(1);

void newnode(int &dir, int p, int H, char w0t) {
	t.push_back(node(p,H,w0t));
	dir = (int)t.size() - 1;
}

int version_cnt = 0;
int root;
int where[1000005];
int sp[20][1000005];

void add_node(int u, int p) {
	sp[0][u] = p;
	for(int i=1; i<=19; i++) {
		sp[i][u] = sp[i-1][sp[i-1][u]];
	}
}

int kth_parent(int u, int k) {
	for(int i=19; i>=0; i--) {
		if(k & (1 << i)) {
			u = sp[i][u];
		}
	} return u;
}

void Init() {
	newnode(where[version_cnt], 0, 0, 'a');
}

void TypeLetter(char L) {
	L -= 'a';
	int u = where[version_cnt];
	if(t[u].to[L] == 0) {
		newnode(t[u].to[L], u, t[u].h + 1, L + 'a');
	} version_cnt++;
	where[version_cnt] = t[u].to[L];
	u = where[version_cnt];
	add_node(u, t[u].par);
}

void UndoCommands(int U) {
	version_cnt++;
	where[version_cnt] = where[version_cnt - U - 1];
}

char GetLetter(int P) {
	P++;
	int u = where[version_cnt];
	return t[kth_parent(u, t[u].h - P)].wot;
}

컴파일 시 표준 에러 (stderr) 메시지

scrivener.cpp: In function 'int myrand(int, int)':
scrivener.cpp:16:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
  ^~
scrivener.cpp:16:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
                          ^~~
scrivener.cpp: In function 'void TypeLetter(char)':
scrivener.cpp:78:14: warning: array subscript has type 'char' [-Wchar-subscripts]
  if(t[u].to[L] == 0) {
              ^
scrivener.cpp:79:20: warning: array subscript has type 'char' [-Wchar-subscripts]
   newnode(t[u].to[L], u, t[u].h + 1, L + 'a');
                    ^
scrivener.cpp:81:32: warning: array subscript has type 'char' [-Wchar-subscripts]
  where[version_cnt] = t[u].to[L];
                                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...