Submission #720350

# Submission time Handle Problem Language Result Execution time Memory
720350 2023-04-08T04:35:36 Z yellowtoad Type Printer (IOI08_printer) C++17
90 / 100
1000 ms 41796 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int n, cnt, b[1000000];
char a[1000000];
string s;
vector<pair<int,int>> trie[1000000];
vector<char> ans;

int dfs(int u, int depth) {
	int maxx = depth;
	for (int i = 0; i < trie[u].size(); i++) {
		trie[u][i].first = dfs(trie[u][i].second,depth+1);
		maxx = max(maxx,trie[u][i].first);
	}
	sort(trie[u].begin(),trie[u].end());
	return maxx;
}

void dfs1(int u) {
	for (int i = 1; i <= b[u]; i++) ans.push_back('P');
	for (int i = 0; i < trie[u].size(); i++) {
		ans.push_back(a[trie[u][i].second]);
		dfs1(trie[u][i].second);
		ans.push_back('-');
	}
}

int main() {
	cin >> n;
	a[++cnt] = ' ';
	for (int i = 1; i <= n; i++) {
		cin >> s;
		int u = 1;
		for (int j = 0; j < s.length(); j++) {
			for (int k = 0; k < trie[u].size(); k++) {
				if (a[trie[u][k].second] == s[j]) {
					u = trie[u][k].second;
					goto skip;
				}
			}
			a[++cnt] = s[j];
			trie[u].push_back({0,cnt});
			u = cnt;
			skip:;
		}
		b[u]++;
	}
	dfs(1,0);
	dfs1(1);
	while (ans.back() == '-') ans.pop_back();
	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
}

Compilation message

printer.cpp: In function 'int dfs(int, int)':
printer.cpp:14:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for (int i = 0; i < trie[u].size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~
printer.cpp: In function 'void dfs1(int)':
printer.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  for (int i = 0; i < trie[u].size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:37:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   for (int j = 0; j < s.length(); j++) {
      |                   ~~^~~~~~~~~~~~
printer.cpp:38:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |    for (int k = 0; k < trie[u].size(); k++) {
      |                    ~~^~~~~~~~~~~~~~~~
printer.cpp:55:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |  for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
      |                  ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23764 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23696 KB Output is correct
2 Correct 13 ms 23724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23780 KB Output is correct
2 Correct 24 ms 23892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 24048 KB Output is correct
2 Correct 37 ms 24136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 24796 KB Output is correct
2 Correct 149 ms 26032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 175 ms 26412 KB Output is correct
2 Correct 66 ms 24388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 433 ms 30300 KB Output is correct
2 Correct 950 ms 38884 KB Output is correct
3 Correct 505 ms 31516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 371 ms 28752 KB Output is correct
2 Execution timed out 1075 ms 41796 KB Time limit exceeded
3 Halted 0 ms 0 KB -