Submission #236846

# Submission time Handle Problem Language Result Execution time Memory
236846 2020-06-03T15:00:42 Z keta_tsimakuridze Type Printer (IOI08_printer) C++14
0 / 100
154 ms 95864 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);
	scanf("%d" , &n);
	for(k=1;k<=n;k++){
		scanf("%s" , &s);
		if(s.size()>s1.size()){
			s1=s;
		}
		add(s);
	}
	
	
	check(s1);
	
	dfs(0);
	i=ans.size()-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: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++){
              ~^~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:53:18: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'std::__cxx11::string* {aka std::__cxx11::basic_string<char>*}' [-Wformat=]
   scanf("%s" , &s);
                ~~^
printer.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d" , &n);
  ~~~~~^~~~~~~~~~~
printer.cpp:53: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 Runtime error 81 ms 95736 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 85 ms 95608 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 86 ms 95736 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 88 ms 95864 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 85 ms 95656 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 84 ms 95736 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 81 ms 95736 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 154 ms 95608 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 85 ms 95864 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 83 ms 95736 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -