답안 #468513

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
468513 2021-08-28T15:50:46 Z mariowong Type Printer (IOI08_printer) C++14
30 / 100
54 ms 19180 KB
#include <bits/stdc++.h>
#define hmod (long long)1223334444555553
using namespace std;

int n,len,mx,indx,cnt,now,tmp,sum;
string s[25005];
char node[500005];
bool build,gg;
vector <int> edge[500005];
bool p[500005];
vector <char> ans;
void dfs(int x){
	if (x != 0) ans.push_back(node[x]); 
	if (p[x]) ans.push_back('P'); 
	for (int i=0;i<edge[x].size();i++){
		dfs(edge[x][i]);
	}
	if (now == x) gg=true;
	ans.push_back('-');
}
int main(){
	ios::sync_with_stdio(false);
	//freopen("typ7b.in","r",stdin); 
	cin >> n;
	for (int i=1;i<=n;i++){
		now=0; 
		cin >> s[i]; len=s[i].length();
		if (len > mx){
			mx=len;
			indx=i;
		}
		for (int j=0;j<len;j++){
			build=true;
			for (int k=0;k<edge[now].size();k++){
				if (node[edge[now][k]] == s[i][j]){
					now=edge[now][k];
					build=false;
				}
			}
			if (build){
				edge[now].push_back(++cnt);
				node[cnt]=s[i][j];
				now=cnt;
			}
		}
		p[now]=true;
	} 
	len=s[indx].length(); now=0;
	for (int i=0;i<len;i++){
		for (int j=0;j<edge[now].size();j++){
			if (node[edge[now][j]] == s[indx][i]){
				tmp=edge[now][j];
				edge[now].erase(edge[now].begin()+j); edge[now].push_back(tmp);
				now=tmp;
				break;
			}
		}
	}
	dfs(0);
	cout << (int)ans.size()-mx-1 << "\n";
	for (int i=0;i<(int)ans.size()-mx-1;i++){
		cout << ans[i] << "\n";
	}
    return 0;
}
/*
8
xxvebmc
ixhvdhcjxon
hsspmkly
labfaryosskugbkiuffd
yerx
mhgpafawzhnt
eejzatjmnqxctn
n


*/

Compilation message

printer.cpp: In function 'void dfs(int)':
printer.cpp:15:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  for (int i=0;i<edge[x].size();i++){
      |               ~^~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:34:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |    for (int k=0;k<edge[now].size();k++){
      |                 ~^~~~~~~~~~~~~~~~~
printer.cpp:50:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   for (int j=0;j<edge[now].size();j++){
      |                ~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 12748 KB Output is correct
2 Correct 9 ms 12748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12748 KB Output is correct
2 Correct 8 ms 12748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12796 KB Output is correct
2 Correct 8 ms 12748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 12748 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12748 KB Output is correct
2 Incorrect 10 ms 13004 KB printed invalid word
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 13012 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 13884 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 15332 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 54 ms 19180 KB printed invalid word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 48 ms 17476 KB printed invalid word
2 Halted 0 ms 0 KB -