Submission #477884

# Submission time Handle Problem Language Result Execution time Memory
477884 2021-10-04T10:50:15 Z starplat Type Printer (IOI08_printer) C++14
30 / 100
116 ms 48696 KB
#include <bits/stdc++.h>
using namespace std;
vector<char> order,ans;
int n,mxlen,ct,vis[550005];
string s,mxs;
struct node{
	int word,ac[30],go;
}trie[550005];
void add(string x,bool ok)
{
	int curr=0;
	for (int i=0;i<x.length();i++){
		if (!trie[curr].ac[x[i]-'a']) trie[curr].ac[x[i]-'a']=++ct;
		curr=trie[curr].ac[x[i]-'a'];
		trie[curr].go=ok;
	}
	trie[curr].word=1;
}
void dfs(int curr)
{
	if (trie[curr].word) ans.push_back('P');
	int dumb=0;
	for (int i=0;i<26;i++){
		if (!trie[curr].ac[i]) continue;
		int node=trie[curr].ac[i];
		if (trie[node].go) dumb=i;
		else {
			ans.push_back(char(i+'a'));
			dfs(node);
			ans.push_back('-');
		}
	}
	if (dumb){
		ans.push_back(char(dumb+'a'));
		dfs(trie[curr].ac[dumb]);
	}
}
int main()
{
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>s;
		if (s.length()>mxlen) mxlen=s.length(),mxs=s;
		add(s,0);
	}
	add(mxs,1);
	dfs(0);
	cout<<ans.size()<<"\n";
	for (char c:ans) cout<<c<<"\n";
}

Compilation message

printer.cpp: In function 'void add(std::string, bool)':
printer.cpp:12:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |  for (int i=0;i<x.length();i++){
      |               ~^~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:43:17: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |   if (s.length()>mxlen) mxlen=s.length(),mxs=s;
      |       ~~~~~~~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB didn't print every word
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1100 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 3600 KB Output is correct
2 Correct 17 ms 7372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 8648 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 61 ms 21444 KB Output is correct
2 Incorrect 116 ms 48696 KB didn't print every word
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 16700 KB didn't print every word
2 Halted 0 ms 0 KB -