Submission #468520

# Submission time Handle Problem Language Result Execution time Memory
468520 2021-08-28T15:56:21 Z mariowong Type Printer (IOI08_printer) C++14
100 / 100
117 ms 31164 KB
#include <bits/stdc++.h>
#define hmod (long long)1223334444555553
using namespace std;

int n,len,mx,indx,cnt,now,tmp;
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]);
	}
	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;
					break;
				}
			}
			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:33:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |    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++){
      |                ~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12748 KB Output is correct
2 Correct 8 ms 12768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12748 KB Output is correct
2 Correct 8 ms 12740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12796 KB Output is correct
2 Correct 8 ms 12848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12748 KB Output is correct
2 Correct 9 ms 12768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12772 KB Output is correct
2 Correct 10 ms 13004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 13004 KB Output is correct
2 Correct 10 ms 13132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 13792 KB Output is correct
2 Correct 22 ms 14992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 15296 KB Output is correct
2 Correct 15 ms 13744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 19156 KB Output is correct
2 Correct 105 ms 28240 KB Output is correct
3 Correct 58 ms 21188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 17344 KB Output is correct
2 Correct 117 ms 31164 KB Output is correct
3 Correct 64 ms 22376 KB Output is correct
4 Correct 101 ms 30164 KB Output is correct