Submission #63370

# Submission time Handle Problem Language Result Execution time Memory
63370 2018-08-01T15:09:10 Z TuGSGeReL Type Printer (IOI08_printer) C++14
30 / 100
106 ms 40524 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=-1;
	}
};
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'];
	}
	root->h=1;
}
void nem(trie* root){
	if(root->h==1) ans.pub('P');
	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:63: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 6 ms 3704 KB Output is correct
2 Correct 6 ms 3940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3940 KB Output is correct
2 Correct 6 ms 3940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3940 KB Output is correct
2 Incorrect 6 ms 3940 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3956 KB Output is correct
2 Correct 6 ms 4008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 4180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 5464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 9816 KB Output is correct
2 Incorrect 39 ms 16360 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 18496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 106 ms 40524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 86 ms 40524 KB Output isn't correct
2 Halted 0 ms 0 KB -