답안 #236858

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
236858 2020-06-03T15:15:40 Z keta_tsimakuridze Type Printer (IOI08_printer) C++14
100 / 100
165 ms 78512 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 ans;
char s[25],s1[25];
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(){
 
	scanf("%d" , &n); 
	for(k=1;k<=n;k++){
		scanf("%s", s);
		if(strlen(s) > strlen(s1)){
			strcpy(s1 , s);
		}
		add(s);
	}
	
	
	check(s1);
	
	dfs(0);
	i=ans.size()-1;
	while(ans[i]=='-'){
		i--;
	}
	printf("%d\n" , i + 1);
	for(k=0;k<=i;k++){
		printf("%c\n",ans[k]);
	}
}

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:11: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:25:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<s.size();i++){
          ~^~~~~~~~~
printer.cpp:27: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:37:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<V[u].size();i++){
              ~^~~~~~~~~~~~
printer.cpp:42:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<V[u].size();i++){
              ~^~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d" , &n); 
  ~~~~~^~~~~~~~~~~
printer.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", s);
   ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 47352 KB Output is correct
2 Correct 32 ms 47356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 47360 KB Output is correct
2 Correct 32 ms 47352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 47360 KB Output is correct
2 Correct 31 ms 47232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 47360 KB Output is correct
2 Correct 33 ms 47360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 47352 KB Output is correct
2 Correct 34 ms 47616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 47736 KB Output is correct
2 Correct 34 ms 47864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 49144 KB Output is correct
2 Correct 48 ms 51064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 51848 KB Output is correct
2 Correct 40 ms 48376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 58516 KB Output is correct
2 Correct 142 ms 73520 KB Output is correct
3 Correct 95 ms 60564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 55700 KB Output is correct
2 Correct 165 ms 78512 KB Output is correct
3 Correct 101 ms 62484 KB Output is correct
4 Correct 139 ms 76848 KB Output is correct