# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
155621 | karma | Type Printer (IOI08_printer) | C++14 | 201 ms | 100660 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>
#define Task "test"
#define pb emplace_back
using namespace std;
const int N = 25001;
const int nAlpha = 26;
string s[N];
int n, res, Max;
struct TNode {
int finish;
TNode* chil[nAlpha];
} *root;
typedef TNode* PNode;
PNode Add() {
++res;
PNode ptr = new TNode();
ptr -> finish = 0;
for(int i = 0; i < nAlpha; ++i) ptr -> chil[i] = NULL;
return ptr;
}
void Ins(string s) {
PNode ptr = root;
for(int i = 0; i < int(s.size()); ++i) {
s[i] -= 'a';
if(ptr -> chil[s[i]] == NULL) ptr -> chil[s[i]] = Add();
ptr = ptr -> chil[s[i]];
}
++ptr -> finish;
}
void Trace(PNode ptr, int depth, bool keep, char letter) {
if(ptr != root) cout << letter << '\n';
for(int i = 0; i < nAlpha; ++i) {
if(ptr -> chil[i] == NULL) continue;
if(!keep) Trace(ptr -> chil[i], depth + 1, 0, char('a' + i));
else if(i != s[Max][depth] - 'a') Trace(ptr -> chil[i], depth + 1, 0, char('a' + i));
}
if(ptr -> finish) cout << "P\n";
if(keep && depth < int(s[Max].size())) {
if(ptr -> chil[s[Max][depth] - 'a']) Trace(ptr -> chil[s[Max][depth] - 'a'], depth + 1, 1, s[Max][depth]);
}
if(!keep) cout << "-\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
if(fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
}
cin >> n; s[Max = 0] = "";
res = -1; root = Add();
for(int i = 1; i <= n; ++i) {
cin >> s[i]; Ins(s[i]);
if(int(s[Max].size()) < int(s[i].size())) Max = i;
}
res = res * 2 + n - s[Max].size();
cout << res << '\n';
Trace(root, 0, 1, 'a');
}
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... |