Submission #236810

# Submission time Handle Problem Language Result Execution time Memory
236810 2020-06-03T12:05:48 Z nickmet2004 Type Printer (IOI08_printer) C++11
0 / 100
89 ms 58108 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];
char ans[1000005] , s1[21];
char s[21];
int I;
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[I]+='P';  I++;}
	for(int i=0;i<V[u].size();i++){
		if(f[V[u][i].second]) continue;
		ans[I]+=V[u][i].first; I++;
		dfs(V[u][i].second);
	}
	for(int i=0;i<V[u].size();i++){
		if(f[V[u][i].second]){
		ans[I]+=V[u][i].first; I++;
			dfs(V[u][i].second);
		}
	}
	ans[I]+='-'; I++;
}
int main(){
ios_base::sync_with_stdio(false);
	cin>>n;
	for(k=1;k<=n;k++){
		scanf("%s" , &s);
		if(strlen(s) > strlen(s1)) strcpy(s1 , s);
		add(s);
	}


	check(s1);

	dfs(0);
	i=strlen(ans)-1;
	while(ans[i]=='-'){
		i--;
	}
	printf("%d\n" , i + 1);
	for(k=0;k<=i;k++){
		printf("%c\n" , ans[k]);
	}
}

Compilation message

printer.cpp: In function 'void add(std::__cxx11::string)':
printer.cpp:10:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<s.size();i++){
          ~^~~~~~~~~
printer.cpp:12: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:26:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<s.size();i++){
          ~^~~~~~~~~
printer.cpp:28: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:38:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<V[u].size();i++){
              ~^~~~~~~~~~~~
printer.cpp:43:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<V[u].size();i++){
              ~^~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:55:18: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[21]' [-Wformat=]
   scanf("%s" , &s);
                ~~^
printer.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s" , &s);
   ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 47360 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 47360 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 47488 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 47356 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 47372 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 47336 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 48640 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 53 ms 51364 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 89 ms 58108 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 85 ms 55288 KB printed invalid word
2 Halted 0 ms 0 KB -