Submission #1099821

# Submission time Handle Problem Language Result Execution time Memory
1099821 2024-10-12T05:29:50 Z horezushol Type Printer (IOI08_printer) C++14
10 / 100
9 ms 12888 KB
#include<bits/stdc++.h>
#define F first
#define S second
#define SZ(x) int((x).size())
const char nl = '\n';
using ll = long long;
using namespace std;

const int N = 25100;
int nam = 0;
int n;
int trie[N][27];
int dp[N][27];
int dep[N][27];
bool stop[N];

void add(string s) {
	int x = 0;
	for (auto c : s) {
		if (!trie[x][c-'a']) {
			trie[x][c-'a'] = ++nam;
		}
		dep[x][c-'a'] = max(dep[x][c-'a'], SZ(s));
		x = trie[x][c-'a'];
	}
	stop[x] = true;
}

vector<char> res;
int fine = 0;
void dfs(int x) {
	if (stop[x]) {
		res.push_back('P');
		fine ++;
	}
	vector<int> topo(27, 0);
	iota(topo.begin(), topo.end(), 0);
	sort(topo.begin(), topo.end(), [&](int a, int b) {
		return dp[x][a] < dp[x][b];
	});
	for (auto c : topo) {
		if (!trie[x][c]) {
			continue;
		}
		res.push_back(c + 'a');
		dfs(trie[x][c]);
	}
	if (fine != n) {
		res.push_back('-');
	}
}

void verkefni() {
	cin >> n;
	string s[n];
	for (int i = 0; i < n; i ++) {
		cin >> s[i];
		add(s[i]);
	}
	dfs(0);
	cout << SZ(res) << nl;
	for (auto el : res) {
		cout << el << nl;
	}
	// for (int i = 0; i <= nam; i ++) {
	// 	for (int j = 0; j < 27; j ++) {
	// 		if (trie[i][j]) {
	// 			cout << "[" << i << ", " << j << "] --> " << trie[i][j] << nl;
	// 			cout << "[" << i << ", " << j << "] --> " << dep[i][j] << nl;
	// 		}
	// 	}
	// }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tst = 1;
// 	cin >> tst;
	while (tst --) {
		verkefni();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 5976 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 11868 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 12636 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 12888 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -