Submission #226891

# Submission time Handle Problem Language Result Execution time Memory
226891 2020-04-25T15:54:16 Z keta_tsimakuridze Type Printer (IOI08_printer) C++14
80 / 100
1000 ms 88752 KB
#include<bits/stdc++.h>
using namespace std;
int k,n,i,cur,aft[1000005][28],f[1000005],endd[1000005];
vector< pair<char,int> >V[1000005];
string s,ans,s1;
void add(string s){
	int u=0;
	for(i=0;i<s.size();i++){
		if(aft[u][(int)s[i]-'a'+1]==0){
			cur++;
			aft[u][(int)s[i]-'a'+1]=cur; V[u].push_back({s[i],cur});
		}
		u=aft[u][(int)s[i]-'a'+1];
	}
	endd[u]=1;
}
void check(string s){
	int u=0;
	for(i=0;i<s.size();i++){
		f[aft[u][(int)s[i]-'a'+1]]=1;
		u=aft[u][(int)s[i]-'a'+1];
	}
}
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(){
	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]<<endl;
	}
}

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: In function 'void check(std::__cxx11::string)':
printer.cpp:19:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<s.size();i++){
          ~^~~~~~~~~
printer.cpp: In function 'void dfs(int)':
printer.cpp:26:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<V[u].size();i++){
              ~^~~~~~~~~~~~
printer.cpp:31: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 Correct 20 ms 23808 KB Output is correct
2 Correct 17 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23808 KB Output is correct
2 Correct 17 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Correct 17 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Correct 19 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23936 KB Output is correct
2 Correct 35 ms 24320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 24832 KB Output is correct
2 Correct 53 ms 25148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 27520 KB Output is correct
2 Correct 241 ms 31992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 292 ms 33468 KB Output is correct
2 Correct 101 ms 25848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 716 ms 47916 KB Output is correct
2 Execution timed out 1098 ms 78636 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 582 ms 42264 KB Output is correct
2 Execution timed out 1102 ms 88752 KB Time limit exceeded
3 Halted 0 ms 0 KB -