# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
916949 | SonicML | Type Printer (IOI08_printer) | C++14 | 104 ms | 49936 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 <iostream>
#include <fstream>
using namespace std;
int n, gSize;
int const NMAX = 5e5;
int g[1 + NMAX]['z' - 'a' + 1];
int finish[1 + NMAX];
int printed = 0;
string big = "";
string ans = "";
void DFS(int node, int depth) {
for(int i = 1;i <= finish[node];i++) {
ans.push_back('P');
printed++;
}
for(char c = 'a';c <= 'z';c++) {
int to = g[node][c - 'a'];
if(to && (depth >= big.size() || c != big[depth])) {
ans.push_back(c);
DFS(to, depth+1);
if(printed < n) {
ans.push_back('-');
}
}
}
if(depth < big.size() && g[node][big[depth] - 'a']) {
int to = g[node][big[depth] - 'a'];
ans.push_back(big[depth]);
DFS(to, depth+1);
if(printed < n) {
ans.push_back('-');
}
}
}
int main() {
cin >> n;
string s;
for(int i = 1;i <= n;i++) {
cin >> s;
int node = 0;
for(int pos = 0;pos < s.size();pos++) {
if(g[node][s[pos] - 'a'] == 0) {
gSize++;
g[node][s[pos] - 'a'] = gSize;
}
node = g[node][s[pos] - 'a'];
}
if(big.size() < s.size()) {
big = s;
}
finish[node]++;
}
//cerr << big << '\n';
DFS(0, 0);
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... |