답안 #226892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
226892 2020-04-25T15:56:36 Z keta_tsimakuridze Type Printer (IOI08_printer) C++14
80 / 100
1000 ms 88864 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(){
	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++){
              ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Correct 17 ms 23808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Correct 17 ms 23808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Correct 17 ms 23808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23808 KB Output is correct
2 Correct 17 ms 23808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23936 KB Output is correct
2 Correct 31 ms 24320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 24832 KB Output is correct
2 Correct 52 ms 25088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 27640 KB Output is correct
2 Correct 233 ms 31864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 305 ms 33544 KB Output is correct
2 Correct 112 ms 26012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 715 ms 47796 KB Output is correct
2 Execution timed out 1097 ms 78596 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 553 ms 42388 KB Output is correct
2 Execution timed out 1097 ms 88864 KB Time limit exceeded
3 Halted 0 ms 0 KB -