Submission #65014

# Submission time Handle Problem Language Result Execution time Memory
65014 2018-08-06T12:28:51 Z TuGSGeReL Type Printer (IOI08_printer) C++14
10 / 100
116 ms 40908 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=25;i>=0;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 3832 KB Output is correct
2 Correct 5 ms 3832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3928 KB Output is correct
2 Incorrect 6 ms 4096 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 4096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 4096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4232 KB Output is correct
2 Incorrect 7 ms 4860 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 5652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 9824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 18688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 116 ms 40908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 103 ms 40908 KB Output isn't correct
2 Halted 0 ms 0 KB -