Submission #683907

# Submission time Handle Problem Language Result Execution time Memory
683907 2023-01-19T15:46:53 Z abcdehello Type Printer (IOI08_printer) C++17
80 / 100
1000 ms 147844 KB
#include <bits/stdc++.h>
using namespace std;
struct node{
	int ch;
	bool print=false,lst=false;
	vector<int> nxt;
};
node trie[1000050];
int n,nxt=1;
vector<string> ss,longest;
vector<char> ans;
void dfs(int u){
	cerr << "trav " << u << endl;
	if (u>0) ans.push_back(trie[u].ch);
	if (trie[u].print) ans.push_back('P');
	int lst=-1;
	for (int i=0;i<26;i++){
		if (trie[u].nxt[i]==-1) continue;
		if (trie[trie[u].nxt[i]].lst){
			lst=trie[u].nxt[i]; continue;
		}
		dfs(trie[u].nxt[i]);
	}
	if (lst>0) dfs(lst);
	else ans.push_back('-');
}
bool comp(string a,string b){
	if (a.length()!=b.length()) return a.length()<b.length();
	return a<b;
}
int main(){
	for (int i=0;i<1000050;i++){
		trie[i].nxt.resize(26);
		for (int j=0;j<26;j++){
			trie[i].nxt[j]=-1;
		}
	}
	cin >> n;
	for (int i=0;i<n;i++){
		string s;
		cin >> s;
		ss.push_back(s);
		int cur=0;
		for (int j=0;j<s.length();j++){
			if (trie[cur].nxt[s[j]-'a']==-1){
				trie[cur].nxt[s[j]-'a']=nxt++;
				trie[nxt-1].ch=s[j];
			}
			cur=trie[cur].nxt[s[j]-'a'];
		}
		trie[cur].print=1;
	}
	sort(ss.begin(),ss.end(),comp);
	string lst=ss.back();
	int cur=0;
	for (int i=0;i<lst.length();i++){
		cur=trie[cur].nxt[lst[i]-'a'];
		trie[cur].lst=1;
	}
	cerr << endl;
	dfs(0);
	ans.pop_back();
	cout << ans.size() << "\n";
	for (auto i:ans) cout << i << "\n";
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:44:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |   for (int j=0;j<s.length();j++){
      |                ~^~~~~~~~~~~
printer.cpp:56:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |  for (int i=0;i<lst.length();i++){
      |               ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 107 ms 141104 KB Output is correct
2 Correct 103 ms 141132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 141132 KB Output is correct
2 Correct 106 ms 141204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 141200 KB Output is correct
2 Correct 109 ms 141112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 141320 KB Output is correct
2 Correct 108 ms 141164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 141188 KB Output is correct
2 Correct 126 ms 141288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 141340 KB Output is correct
2 Correct 150 ms 141420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 202 ms 141924 KB Output is correct
2 Correct 312 ms 142568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 359 ms 142888 KB Output is correct
2 Correct 176 ms 142196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 734 ms 145388 KB Output is correct
2 Execution timed out 1090 ms 147380 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 605 ms 144996 KB Output is correct
2 Execution timed out 1091 ms 147844 KB Time limit exceeded
3 Halted 0 ms 0 KB -