답안 #477862

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477862 2021-10-04T08:47:59 Z starplat Type Printer (IOI08_printer) C++14
0 / 100
57 ms 40640 KB
#include <bits/stdc++.h>
using namespace std;
vector<char> order,ans;
int n,mxlen,ct,vis[550005];
string s,mxs;
struct node{
	int word,ac[30];
}trie[550005];
void add(string x)
{
	int curr=0;
	for (int i=0;i<x.length();i++){
		if (!trie[curr].ac[x[i]-'a']) trie[curr].ac[x[i]-'a']=++ct;
		curr=trie[curr].ac[x[i]-'a'];
	}
	trie[curr].word=1;
}
void dfs(int curr,char x)
{
	ans.push_back(x);
	if (trie[curr].word) ans.push_back('P');
	for (int i=0;i<26;i++){
		if (!trie[curr].ac[i]) continue;
		dfs(trie[curr].ac[i],char(i+'a'));
	}
	ans.push_back('-');
}
void final(int curr,char x,int lvl,int ok)
{
	ans.push_back(x);
	if (trie[curr].word) ans.push_back('P');
	for (int i=0;i<26;i++){
		if (!trie[curr].ac[i]) continue;
		if (mxs[lvl]!=char(i+'a')&&!ok||ok)final(trie[curr].ac[i],char(i+'a'),lvl+1,1);
	}
	if (ok==1) ans.push_back('-');
}
int main()
{
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>s;
		if (s.length()>mxlen) mxlen=s.length(),mxs=s;
		add(s);
	}
	mxs=mxs+' ';
	for (int i=0;i<26;i++){
		if (char(i+'a')==mxs[0]) continue;
		if (!trie[0].ac[i]) continue;
		dfs(trie[0].ac[i],char(i+'a'));
	}
	for (int i=0;i<mxs.length()-1;i++){
		int curr=trie[curr].ac[mxs[i]-'a'];
		final(curr,mxs[i],i+1,0);
	}
	//cout<<ans.size()<<" "<<mxlen<<"\n";
	cout<<ans.size()<<"\n";
	for (int i=0;i<ans.size();i++) cout<<ans[i]<<"\n";
}

Compilation message

printer.cpp: In function 'void add(std::string)':
printer.cpp:12:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |  for (int i=0;i<x.length();i++){
      |               ~^~~~~~~~~~~
printer.cpp: In function 'void final(int, char, int, int)':
printer.cpp:34:28: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   34 |   if (mxs[lvl]!=char(i+'a')&&!ok||ok)final(trie[curr].ac[i],char(i+'a'),lvl+1,1);
printer.cpp: In function 'int main()':
printer.cpp:43:17: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |   if (s.length()>mxlen) mxlen=s.length(),mxs=s;
      |       ~~~~~~~~~~^~~~~~
printer.cpp:52:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for (int i=0;i<mxs.length()-1;i++){
      |               ~^~~~~~~~~~~~~~~
printer.cpp:58:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for (int i=0;i<ans.size();i++) cout<<ans[i]<<"\n";
      |               ~^~~~~~~~~~~
printer.cpp:53:36: warning: 'curr' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |   int curr=trie[curr].ac[mxs[i]-'a'];
      |                                    ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 384 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 400 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 2124 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 6744 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 23 ms 16460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 57 ms 40640 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 51 ms 31796 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -