답안 #477883

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477883 2021-10-04T10:48:16 Z starplat Type Printer (IOI08_printer) C++14
30 / 100
126 ms 48660 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],go;
}trie[550005];
void add(string x,bool ok)
{
	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].go=ok;
	}
	trie[curr].word=1;
}
void dfs(int curr,char c)
{
	if (curr) ans.push_back(c);
	if (trie[curr].word) ans.push_back('P');
	int dumb=0;
	for (int i=0;i<26;i++){
		if (!trie[curr].ac[i]) continue;
		int node=trie[curr].ac[i];
		if (trie[node].go) dumb=i;
		else {
			dfs(node,char(i+'a'));
			ans.push_back('-');
		}
	}
	if (dumb){
		dfs(trie[curr].ac[dumb],dumb+'a');
	}
}
int main()
{
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>s;
		if (s.length()>mxlen) mxlen=s.length(),mxs=s;
		add(s,0);
	}
	add(mxs,1);
	dfs(0,'1');
	cout<<ans.size()<<"\n";
	for (char c:ans) cout<<c<<"\n";
}

Compilation message

printer.cpp: In function 'void add(std::string, bool)':
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 'int main()':
printer.cpp:42:17: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |   if (s.length()>mxlen) mxlen=s.length(),mxs=s;
      |       ~~~~~~~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB didn't print every word
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1100 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 3532 KB Output is correct
2 Correct 18 ms 7372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 8704 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 21384 KB Output is correct
2 Incorrect 126 ms 48660 KB didn't print every word
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 49 ms 16684 KB didn't print every word
2 Halted 0 ms 0 KB -