# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
922062 | Syrius | Type Printer (IOI08_printer) | C++14 | 124 ms | 99536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define ll long long
#define ff first
#define ss second
#define pint pair < int , int >
#define fast ios_base::sync_with_stdio(NULL); cin.tie(NULL)
const int inf = 1e9 + 9;
const int mxn = 1e6 + 2;
const int mod = 1e9 + 7;
struct node {
bool ends , path;
node *branch[26];
node () {
ends = path = 0;
for (int i = 0; i < 26; i++) branch[i] = NULL;
}
};
void insert(node *root , string s) {
for (int i = 0; i < s.size(); i++) {
int id = s[i] - 'a';
if (root -> branch[id] == NULL) root -> branch[id] = new node();
root = root -> branch[id];
}
root -> ends = 1;
}
void createpath(node *root , string s) {
for (int i = 0; i < s.size(); i++) {
int id = s[i] - 'a';
root -> branch[id] -> path = 1;
root = root -> branch[id];
}
}
vector < char > ans;
void print(node *root) {
node *go = NULL;
char add;
if (root -> ends) ans.push_back('P');
for (int i = 0; i < 26; i++) {
if (root -> branch[i] == NULL) continue;
if (root -> branch[i] -> path) {
go = root -> branch[i];
add = i + 'a';
continue;
}
ans.push_back(i + 'a');
print(root -> branch[i]);
ans.push_back('-');
}
if (go != NULL) {
ans.push_back(add);
print(go);
}
}
int main() {
int n;
cin >> n;
node *root = new node();
string mx;
int sz = 0;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
insert(root , s);
if (s.size() > sz) {
mx = s;
sz = s.size();
}
}
createpath(root , mx);
print(root);
cout << ans.size() << '\n';
for (int i = 0; i < ans.size(); i++) cout << ans[i] << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |