# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
212279 | jk89 | Type Printer (IOI08_printer) | C++14 | 109 ms | 48628 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 <cstring>
#include <vector>
using namespace std;
const int MAXN = 5e5 + 3;
const int ALF = 26;
int t[MAXN][ALF];
bool mask[MAXN];
vector<char> odp;
void DFS(int x) {
if (mask[x])
odp.push_back('P');
for (int i = 0; i < ALF; i++) {
if (t[x][i] != 0) {
odp.push_back(char(i + 'a'));
DFS(t[x][i]);
}
}
odp.push_back('-');
}
int main() {
ios_base::sync_with_stdio(false);
int n;
string s, temp;
cin >> n;
int ind = 0;
int akt, x;
int mx = 0;
for (int i = 1; i <= n; i++) {
cin >> s;
if (s.size() > mx) {
mx = s.size();
temp = s;
}
akt = 0;
for (int j = 0; j < s.size(); j++) {
x = s[j] - 'a';
if (t[akt][x] != 0)
akt = t[akt][x];
else {
ind++;
t[akt][x] = ind;
akt = ind;
}
}
mask[akt] = true;
}
akt = 0;
for (int i = 0; i < mx; i++) {
for (int j = 0; j < ALF; j++) {
if (t[akt][j] != 0 && j != temp[i] - 'a') {
odp.push_back(char(j + 'a'));
DFS(t[akt][j]);
}
}
akt = t[akt][temp[i] - 'a'];
odp.push_back(temp[i]);
if (mask[akt])
odp.push_back('P');
}
cout << odp.size() << '\n';
for (auto it:odp)
cout << it << '\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... |