Submission #383783

# Submission time Handle Problem Language Result Execution time Memory
383783 2021-03-30T19:51:00 Z penguinhacker Type Printer (IOI08_printer) C++14
20 / 100
52 ms 18568 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

int n, m, c[500001][26], cnt[500001];
string ans, b;

void dfs(int u = 0) {
	while(cnt[u]) {
		ans.push_back('P');
		--cnt[u];
	}
	for (int i = 0; i < 26; ++i)
		if (c[u][i]) {
			ans.push_back('a' + i);
			dfs(c[u][i]);
			ans.push_back('-');
		}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	m = 1;
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		if (s.size() > b.size())
			b = s;
		int u = 0;
		for (char d : s) {
			if (!c[u][d - 'a'])
				c[u][d - 'a'] = m++;
			u = c[u][d - 'a'];
		}
		++cnt[u];
	}
	int u = 0;
	for (char d : b) {
		for (int i = 0; i < 26; ++i)
			if (c[u][i] && i != d - 'a') {
				ans.push_back('a' + i);
				dfs(c[u][i]);
				ans.push_back('-');
			}
		ans.push_back(d);
		u = c[u][d - 'a'];
	}
	ans += 'P';
	cout << ans.size() << "\n";
	for (char d : ans)
		cout << d << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB didn't print every word
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1260 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 3180 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 7676 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 18568 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 14600 KB didn't print every word
2 Halted 0 ms 0 KB -