Submission #63369

# Submission time Handle Problem Language Result Execution time Memory
63369 2018-08-01T15:03:29 Z TuGSGeReL Type Printer (IOI08_printer) C++14
20 / 100
132 ms 40836 KB
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back
#define ss second
#define ff first
#define ext exit(0)
using namespace std;
struct trie{
	trie *next[26];
	ll h;
	trie(){
		for(int i=0;i<26;i++) next[i]=NULL;
		h=0;
	}
};
ll n,zr[26];
string s[111111];
vector<pair<ll,ll> >v;
vector<char>ans;
void insert(trie *root,string s){
	for(int i=0;i<s.size();i++){
		if(root->next[s[i]-'a']==NULL){
			root->next[s[i]-'a']=new trie();
		}
		root=root->next[s[i]-'a'];
	}
}
void nem(trie* root){
	ll hah=0;
	for(int i=0;i<26;i++){
		if(root->next[i]==NULL)hah++;
	}
	if(hah==26){
		ans.pub('P');
		return ;
	}
	for(int i=0;i<26;i++){
		if(root->next[i]!=NULL){
			ans.pub(char(i+'a'));
			nem(root->next[i]);
			ans.pub('-');
		}
	}
}
void solv(ll k,trie *root){
	root=root->next[k];
	ans.pub(char(k+'a'));
	nem(root);
}
int main (){
	trie *root=new trie();
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s[i];
		ll oo=s[i].size();
		zr[s[i][0]-'a']=max(zr[s[i][0]-'a'],oo);
		insert(root,s[i]);
	}
	for(int i=0;i<26;i++) v.pub(mp(zr[i],i));
	sort(v.begin(),v.end());
	for(int i=0;i<26;i++){
		if(!v[i].ff)continue;
		else solv(v[i].ss,root),ans.pub('-');
	}
	while(ans.back()=='-') ans.pop_back();
	cout<<ans.size()<<"\n";
	for(int i=0;i<ans.size();i++){
		cout<<ans[i]<<"\n";
	}
}

Compilation message

printer.cpp: In function 'void insert(trie*, std::__cxx11::string)':
printer.cpp:23:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<s.size();i++){
              ~^~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:69:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<ans.size();i++){
              ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3704 KB Output is correct
2 Correct 6 ms 3948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3948 KB Output is correct
2 Correct 5 ms 3948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 3988 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3992 KB Output is correct
2 Incorrect 6 ms 4024 KB didn't print every word
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 4232 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 5644 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 9752 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 57 ms 18664 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 132 ms 40836 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 84 ms 40836 KB didn't print every word
2 Halted 0 ms 0 KB -