답안 #226890

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
226890 2020-04-25T15:52:56 Z keta_tsimakuridze Type Printer (IOI08_printer) C++14
80 / 100
1000 ms 108844 KB
#include<bits/stdc++.h>
using namespace std;
int k,n,i,cur,f[1000005],endd[1000005];
map<int,int>aft[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);
	}
	//cout<<cur<<endl;
	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:9: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:21: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:28:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<V[u].size();i++){
              ~^~~~~~~~~~~~
printer.cpp:33:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<V[u].size();i++){
              ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 70784 KB Output is correct
2 Correct 40 ms 70784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 70776 KB Output is correct
2 Correct 40 ms 70776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 70784 KB Output is correct
2 Correct 40 ms 70776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 70784 KB Output is correct
2 Correct 44 ms 70784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 70904 KB Output is correct
2 Correct 55 ms 71288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 71416 KB Output is correct
2 Correct 75 ms 71544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 152 ms 72996 KB Output is correct
2 Correct 274 ms 75640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 345 ms 76424 KB Output is correct
2 Correct 124 ms 72056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 744 ms 85268 KB Output is correct
2 Execution timed out 1091 ms 103088 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 588 ms 81812 KB Output is correct
2 Execution timed out 1100 ms 108844 KB Time limit exceeded
3 Halted 0 ms 0 KB -