Submission #226893

# Submission time Handle Problem Language Result Execution time Memory
226893 2020-04-25T15:57:31 Z keta_tsimakuridze Type Printer (IOI08_printer) C++14
80 / 100
1000 ms 88896 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 j=0;j<V[u].size();j++){
		if(f[V[u][j].second]){
		ans+=V[u][j].first;
			dfs(V[u][j].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]<<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 j=0;j<V[u].size();j++){
              ~^~~~~~~~~~~~
# 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 17 ms 23936 KB Output is correct
2 Correct 18 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23876 KB Output is correct
2 Correct 18 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23808 KB Output is correct
2 Correct 19 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 23936 KB Output is correct
2 Correct 36 ms 24448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 24832 KB Output is correct
2 Correct 54 ms 25088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 120 ms 27716 KB Output is correct
2 Correct 241 ms 32000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 287 ms 33444 KB Output is correct
2 Correct 93 ms 25856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 690 ms 48020 KB Output is correct
2 Execution timed out 1096 ms 78520 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 535 ms 42396 KB Output is correct
2 Execution timed out 1091 ms 88896 KB Time limit exceeded
3 Halted 0 ms 0 KB -