Submission #437996

# Submission time Handle Problem Language Result Execution time Memory
437996 2021-06-27T11:52:40 Z dutch Type Printer (IOI08_printer) C++17
100 / 100
146 ms 48836 KB
#include <bits/stdc++.h>
using namespace std;

const int LIM = 20 * 25000;

array<int, 26> g[LIM];
int a[LIM], toEnd = 0;
bitset<LIM> bad;
pair<int, string> mx = {0, ""};

void dfs(int u){
	while(a[u]--) cout << "P\n";
	if(u == toEnd) exit(0);
	for(int i=0; i<26; ++i){
		if(!g[u][i] || bad[g[u][i]]) continue;
		cout << char('a' + i) << '\n';
		dfs(g[u][i]);
		cout << "-\n";
	}
	for(int i=0; i<26; ++i){
		if(!g[u][i] || !bad[g[u][i]]) continue;
		cout << char('a' + i) << '\n';
		dfs(g[u][i]);
		cout << "-\n";
	}
}

signed main(){
	cin.tie(0)->sync_with_stdio(0);
	int n, cnt = 0; cin >> n;
	for(int i=0; i<n; ++i){
		string s; cin >> s;
		mx = max(mx, {s.size(), s});
		int u = 0;
		for(char c : s){
			if(!g[u][c-'a']) g[u][c-'a'] = ++cnt;
			u = g[u][c-'a'];
		}
		++a[u];
	}
	for(char c : mx.second){
		bad[toEnd = g[toEnd][c-'a']] = 1;
	}
	cout << 2*cnt - mx.first + n << '\n';
	dfs(0);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 972 KB Output is correct
2 Correct 3 ms 1224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3020 KB Output is correct
2 Correct 17 ms 6352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 7244 KB Output is correct
2 Correct 8 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 17804 KB Output is correct
2 Correct 117 ms 41028 KB Output is correct
3 Correct 77 ms 21316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 13892 KB Output is correct
2 Correct 135 ms 48836 KB Output is correct
3 Correct 73 ms 24260 KB Output is correct
4 Correct 146 ms 46084 KB Output is correct