Submission #396169

# Submission time Handle Problem Language Result Execution time Memory
396169 2021-04-29T14:05:14 Z Berted Type Printer (IOI08_printer) C++14
30 / 100
114 ms 43388 KB
#include <iostream>

using namespace std;

const int INF = 1e8;

int N; string ans;
int adj[500001][26], cnt[500001], DP[500001], sz = 0;

inline int newNode()
{
	for (int i = 0; i < 26; i++) adj[sz][i] = -1;
	return sz++;
}

inline void insert(int u, int i, const string& s)
{
	if (i < s.size())
	{
		int &v = adj[u][s[i] - 'a'];
		if (v == -1) {v = newNode();}
		insert(v, i + 1, s); DP[u] = max(DP[u], DP[v]) + 1;
	}
	else {cnt[u]++; DP[u] = 1;}
}

inline void solve(int u, bool m)
{
	int hvy = -1;
	for (int i = 0; i < cnt[u]; i++) ans.push_back('P');
	for (int i = 0; i < 26; i++)
	{
		if (adj[u][i] != -1 && m && (hvy == -1 || DP[adj[u][i]] > DP[adj[u][hvy]])) hvy = i;
	}
	for (int i = 0; i < 26; i++)
	{
		if (adj[u][i] != -1 && hvy != i) 
		{
			ans.push_back(i + 'a');
			solve(adj[u][i], 0);
			ans.push_back('-');
		}
	}
	if (hvy != -1) {ans.push_back(hvy + 'a'); solve(adj[u][hvy], 1);}
}

int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> N;
	newNode();
	for (int i = 0; i < N; i++) {string S; cin >> S; insert(0, 0, S);}
	solve(0, 1);
	cout << ans.size() << "\n";
	for (const char &c : ans) cout << c << "\n";
	return 0;
}

Compilation message

printer.cpp: In function 'void insert(int, int, const string&)':
printer.cpp:18:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  if (i < s.size())
      |      ~~^~~~~~~~~~
# 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 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 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 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 3276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 7772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 18868 KB Output is correct
2 Correct 114 ms 43388 KB Output is correct
3 Incorrect 64 ms 22624 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 14892 KB Output isn't correct
2 Halted 0 ms 0 KB -