Submission #226656

# Submission time Handle Problem Language Result Execution time Memory
226656 2020-04-24T16:59:58 Z tushar_2658 Type Printer (IOI08_printer) C++14
80 / 100
1000 ms 84848 KB
#include "bits/stdc++.h"
using namespace std;

const int maxn = 1000005;
string s[maxn];
int t[maxn][26], ed[maxn], cnt[maxn];
int node = 0;
int par[maxn];

void insert(string s){
	int cur = 0;
	for(auto c : s){
		if(!t[cur][c - 'a']){
			t[cur][c - 'a'] = ++node;
		}
		par[t[cur][c - 'a']] = cur;
		cur = t[cur][c - 'a'];
	}
	ed[cur] = 1;
}

vector<char> v;

void get(int cur){
	cnt[cur] = 1;
	for(int i = 0; i < 26; ++i){
		if(t[cur][i]){
			get(t[cur][i]);
			cnt[cur] = max(cnt[cur], cnt[t[cur][i]] + 1);
		}
	}
}

void dfs(int cur){
	if(ed[cur]){
		ed[cur] = 0;
		v.push_back('P');
	}
	vector<pair<int, int>> vv;
	for(int i = 0; i < 26; ++i){
		if(t[cur][i]){
			vv.push_back(make_pair(cnt[t[cur][i]], i));
		}
	}
	sort(vv.begin(), vv.end());
	for(auto i : vv){
		v.push_back((char)(i.second + 'a'));
		dfs(t[cur][i.second]);
		v.push_back('-');
	}
}

int main(int argc, char const *argv[])
{
//	freopen("in.txt", "r", stdin);
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> s[i];
		insert(s[i]);
	}
	get(0); 	
	dfs(0);
	while(v.back() == '-')v.pop_back();
	cout << v.size() << endl;
	for(auto i : v){
		cout << i << endl;
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 21 ms 31616 KB Output is correct
2 Correct 21 ms 31616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 31616 KB Output is correct
2 Correct 21 ms 31616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 31744 KB Output is correct
2 Correct 22 ms 31688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 31744 KB Output is correct
2 Correct 21 ms 31720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 31796 KB Output is correct
2 Correct 36 ms 32128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 32512 KB Output is correct
2 Correct 57 ms 32768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 127 ms 34808 KB Output is correct
2 Correct 254 ms 38396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 297 ms 39416 KB Output is correct
2 Correct 94 ms 33400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 708 ms 51312 KB Output is correct
2 Execution timed out 1098 ms 76396 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 587 ms 46836 KB Output is correct
2 Execution timed out 1096 ms 84848 KB Time limit exceeded
3 Halted 0 ms 0 KB -