Submission #837846

# Submission time Handle Problem Language Result Execution time Memory
837846 2023-08-25T18:40:16 Z Liudas Type Printer (IOI08_printer) C++17
0 / 100
67 ms 73020 KB
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
const int MAX_SIZE = 26;
struct node{
    node *arr[MAX_SIZE];
    int end;
	int maxi;
};
node *getNode(){
    node *nnode = new node;
	nnode -> end = 0;
	nnode -> maxi = 0;
	for(int i = 0; i < MAX_SIZE; i ++){
		nnode -> arr[i] = NULL;
	}
	return nnode;
}
void insert_node(node *root, string s){
	node *cur = root;
	for(char i : s){
		int	id = i - 'a';
		if(!cur -> arr[id]){
			cur ->arr[id] = getNode();
		}
		cur = cur -> arr[id];
	}
	cur -> end ++;
	cur -> maxi = 1;
}
void DFS1(node *root, string s){
	for(int i = 0; i < MAX_SIZE; i ++){
		if(root -> arr[i]){
			DFS1(root -> arr[i], s + char(i +'a'));
			root -> maxi = max(root -> arr[i] -> maxi + 1, root -> maxi);
		}
	}
}
void DFS(node *root, string &s){
	for(int i = 0; i < root -> end; i ++){
		s.push_back('P');
	}
	for(int i = 0; i < MAX_SIZE; i ++){
		int great = -1;
		for(int j = 0; j < MAX_SIZE; j ++){
			if(root -> arr[i]){
				if(great == -1){
					great = j;
				}
				else if(root -> arr[great] -> maxi < root -> arr[j] -> maxi){
					great = j;
				}
			}
		}
		if(great == -1) break;
		s.push_back(i+'a');
		DFS(root -> arr[i], s);
	}
	s.push_back('-');
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    node *trie = getNode();
    vector<string> arr(N);
    for(string &i : arr){
        cin >> i;
        insert_node(trie, i);
    }
	string ans;
	DFS1(trie, "");
	DFS(trie, ans);
	cout << int(ans.size()) - trie -> maxi << endl;
	for(int i = 0; i < int(ans.size()) - trie -> maxi; i ++){
		cout << ans[i] << endl;
	}
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Integer parameter [name=M] equals to -19, violates the range [0, 10000000]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Integer parameter [name=M] equals to -20, violates the range [0, 10000000]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Integer parameter [name=M] equals to -18, violates the range [0, 10000000]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Integer parameter [name=M] equals to -17, violates the range [0, 10000000]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 3376 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 11604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 27 ms 29184 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 67 ms 73020 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 56 ms 57292 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -