답안 #855098

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855098 2023-09-30T07:08:05 Z vjudge1 Type Printer (IOI08_printer) C++14
0 / 100
195 ms 262144 KB
#include<bits/stdc++.h>
using namespace std;
const int sig=26,nn=25000;
struct node{
	int ch[sig];
	bool mark,end;
}t[nn*20]; 
int sz=0;
void insert(const string& s){
	int u=0;
	for(char c:s){
		int d=c-'a',&cu=t[u].ch[d];
		if(!cu) cu+=sz;
		u=cu;
	}
	t[u].end=true;
}
void dfs(int u,string& ans){
	const node& x=t[u];
	if(x.end) ans+='p';
	int mi=-1;
	for(int i=0;i<sig;i++){
		int v=x.ch[i];
		if(!v) continue;
		if(t[v].mark)
			mi=i;
		else
			ans+=i+'a',dfs(v,ans);
	}
	if(mi=-1)
		ans+=mi+'a',dfs(x.ch[mi],ans);
	ans+='-';
}
int main(){
    int n;
    cin>>n;
    string s,l;
    for(int i=0;i<n;i++){
    	cin>>s,insert(s);
    	if(s.length()>l.length()) l=s;
	}
	for(size_t i=0,u=0;i<l.size();i++)
		u=t[u].ch[l[i]-'a'],t[u].mark=true;
	s.clear(),dfs(0,s);
	while(s.back()=='-') s.pop_back();
	cout<<s.size()<<'\n';
	for(char c:s) cout<<c<<"\n";
	return 0;
}

Compilation message

printer.cpp: In function 'void dfs(int, std::string&)':
printer.cpp:30:7: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   30 |  if(mi=-1)
      |     ~~^~~
printer.cpp:31:26: warning: array subscript -1 is below array bounds of 'const int [26]' [-Warray-bounds]
   31 |   ans+=mi+'a',dfs(x.ch[mi],ans);
      |                   ~~~~~~~^
printer.cpp:5:6: note: while referencing 'node::ch'
    5 |  int ch[sig];
      |      ^~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 170 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 173 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 170 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 169 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 171 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 167 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 185 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 195 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 180 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 183 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -