Submission #855061

# Submission time Handle Problem Language Result Execution time Memory
855061 2023-09-30T03:08:26 Z vjudge1 Type Printer (IOI08_printer) C++17
10 / 100
35 ms 19656 KB
#include <bits/stdc++.h>
using namespace std;
bool vis[2000005], vis1[2000005];
int t[2000005][26];//o --> ch
int k,ans1=0; 
struct Trie {
	int n = 1;
	void update(string s) {
		int o = 1;
		for (int i = 0; i < (int)s.size(); i++) {
			if (!t[o][s[i] - 'a'])
				t[o][s[i] - 'a'] = ++n, o = n;
			else
				o = t[o][s[i] - 'a'];
		}
		vis1[o] = 1; // 结尾
		return;
	}
	void dfs(int o, vector<char>& ans) {
		for(int i=0;i<26;i++){
			if(t[o][i]!=0){
				ans.push_back(i+'a');
				dfs(t[o][i],ans);
			}
		}
		if(vis1[o]==1)ans1++,ans.push_back('P');
		if(ans1!=k)ans.push_back('-');
		return;
	}
};
int main() {
	cin >> k;
	string s;
	Trie tr;
	for (int i = 0; i < k; i++) {
		cin >> s;
		tr.update(s);
	}
	vector<char> ans;
	tr.dfs(1, ans);
	cout << ans.size();
	cout << "\n";
	for (char i : ans)
		cout << i << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 5208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 9432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 19656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 15824 KB Output isn't correct
2 Halted 0 ms 0 KB -