답안 #226904

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
226904 2020-04-25T17:03:50 Z keta_tsimakuridze Type Printer (IOI08_printer) C++14
80 / 100
1000 ms 77404 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);
	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: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++){
              ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 47352 KB Output is correct
2 Correct 34 ms 47360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 47360 KB Output is correct
2 Correct 29 ms 47360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 47360 KB Output is correct
2 Correct 29 ms 47360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 47360 KB Output is correct
2 Correct 29 ms 47352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 47360 KB Output is correct
2 Correct 48 ms 47616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 47864 KB Output is correct
2 Correct 66 ms 48000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 154 ms 49024 KB Output is correct
2 Correct 276 ms 51064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 310 ms 51696 KB Output is correct
2 Correct 105 ms 48248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 693 ms 58512 KB Output is correct
2 Execution timed out 1102 ms 72880 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 572 ms 55548 KB Output is correct
2 Execution timed out 1086 ms 77404 KB Time limit exceeded
3 Halted 0 ms 0 KB -