# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
934440 | bashNewbie | Type Printer (IOI08_printer) | C++17 | 2 ms | 1780 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 <vector>
#include <algorithm>
#include <string>
using namespace std;
#define fast_io ios::sync_with_stdio(0), cin.tie(0)
const int N = 5e3+7, K = 26;
int adj[N][K+1], len;
string ms, ret;
inline void pr(char c) {
ret += c;
}
inline void pr(int c) {
ret += c+'a';
}
void add(string& s) {
int x = 0;
for(char ch: s) {
int c = ch-'a', y = adj[x][c];
if(!y) adj[x][c] = ++len;
x = adj[x][c];
}
adj[x][K] = 1;
}
void dfs(int x, int in, int d) {
int c = in && d < (int)ms.size()? ms[d]-'a': -1;
for(int j = 0; j < K+1; j++) {
int y = adj[x][j];
if(!y) continue;
if(j == K) pr('P'); else {
if(!in || in && j != c) pr(j), dfs(y, 0, d+1);
}
}
if(~c) pr(c), dfs(adj[x][c], 1, d+1);
if(!in) pr('-');
}
int main() {
fast_io;
int n, l = 0; string s;
cin >> n;
for(int i = 0; i < n; i++) {
cin >> s, add(s);
if((int)s.size() > l) l = (int)s.size(), ms = s;
}
dfs(0, 1, 0);
cout << (int)ret.size() << "\n";
for(char c: ret) cout << c << "\n";
}
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... |