Submission #226903

# Submission time Handle Problem Language Result Execution time Memory
226903 2020-04-25T17:03:17 Z keta_tsimakuridze Type Printer (IOI08_printer) C++14
0 / 100
77 ms 58388 KB
#include<bits/stdc++.h>
using namespace std;
int k,n,i,cur,f[1000005],endd[1000005],c,ch;
vector< pair<char,int> >V[1000005],aft[1000005];
string s,ans,s1;
void add(string s){
	int u=0;
	for(i=0;i<s.size();i++){
		int ff=0; 
		for(int j=0;j<aft[u].size();j++)
		if(aft[u][j].first==s[i]){
		ff=1;c=aft[u][j].second;break;}
		if(ff==0){
			cur++;
			aft[u].push_back({s[i],cur}); 
			c=cur; V[u].push_back({s[i],cur});
		}
		u=c;
	}
	endd[u]=1;
}
void check(string s){
	int u=0;
	for(i=0;i<s.size();i++){
		
		for(int j=0;j<aft[u].size();j++)
		if(aft[u][j].first==(int)s[i]){
		c=aft[u][j].second;break;}
		
		f[c]=1;
		u=c;
	}
}
void dfs(int u){
	if(endd[u]!=0) ans+='P';
	for(int i=0;i<V[u].size();i++){
		if(f[V[u][i].second]) continue;
		ans+=V[u][i].first;
		dfs(V[u][i].second);
	}
	for(int i=0;i<V[u].size();i++){
		if(f[V[u][i].second]){
		ans+=V[u][i].first;
			dfs(V[u][i].second);
		}
	}
	ans+='-';
}
int main(){
ios_base::sync_with_stdio(false);
	cin>>n;
	for(k=1;k<=n;k++){
		cin>>s;
		if(s.size()>s1.size()){
			s1=s;
		}
		add(s);
	}
	
	
	check(s1);
	
	dfs(0);
	i=ans.size()-1;
	while(ans[i]=='-'){
		i--;
	}
	cout<<i+1<<endl;
	for(k=0;k<=i;k++){
		cout<<ans[k]<<" ";
	}
}

Compilation message

printer.cpp: In function 'void add(std::__cxx11::string)':
printer.cpp:8:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<s.size();i++){
          ~^~~~~~~~~
printer.cpp:10:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<aft[u].size();j++)
               ~^~~~~~~~~~~~~~
printer.cpp: In function 'void check(std::__cxx11::string)':
printer.cpp:24:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<s.size();i++){
          ~^~~~~~~~~
printer.cpp:26:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<aft[u].size();j++)
               ~^~~~~~~~~~~~~~
printer.cpp: In function 'void dfs(int)':
printer.cpp:36:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<V[u].size();i++){
              ~^~~~~~~~~~~~
printer.cpp:41:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<V[u].size();i++){
              ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 47360 KB Line "t p t t t y k d u y v x j b z h q u p P " doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 47360 KB Line "x x v e b m c P - - - - - - - ... y o s s k u g b k i u f f d P " doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 47360 KB Line "h j x g q k P - - - - - - w d ... l m w f i r l g b d e v j d P " doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 47360 KB Line "k i c t n a a h h r g l a z o ... m s g e n n p d l u r n m v P " doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 47360 KB Line "b P q h h h P - - - - s b s u ... - - e y n o r w r b i z a i P " doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 47744 KB Line "p P i P l c c n c s q i q q y ... v i w g d u d c y b a h u w P " doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 49016 KB Line "r P g i s j m k x s x k v v w ... n i c j t u k m w m l d d z P " doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 51720 KB Line "x P r z j v a f j w e x q P - ... k w z a k q u b h s t c d q P " doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 58388 KB Line "v P a P x t s P - - x e q t P ... o b j b x u w l h z w c h f P " doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 73 ms 55700 KB Line "p P s P q g a c j d y j P - - ... P - - - j t e a r n h d j e P " doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -