# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
878378 | vjudge1 | Type Printer (IOI08_printer) | C++14 | 105 ms | 52760 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>
using namespace std;
string output;
char val[500001];
int m, sz, cnt_print;
bool ed[500001], mk[500001];
struct node{
int son[26], cnt;
}nd[500001];
inline void add(const string &s){
int cur = 0;
for (int i = 0; i < s.size(); i++){
if (!nd[cur].son[s[i] - 'a']){
nd[cur].son[s[i] - 'a'] = ++sz;
}
val[nd[cur].son[s[i] - 'a']] = s[i];
cur = nd[cur].son[s[i] - 'a'];
}
ed[cur] = true;
}
inline void mark(const string &s){
int cur = 0;
for (int i = 0; i < s.size(); i++){
mk[nd[cur].son[s[i] - 'a']] = true;
cur = nd[cur].son[s[i] - 'a'];
}
}
void dfs(const int &x){
if (ed[x] && x != 0){
cnt_print++;
output += 'P';
}
if (cnt_print == m){
cout << output.size() << "\n";
for (int i = 0; i < output.size(); i++){
cout << output[i] << "\n";
}
return;
}
int cur = 0;
for (int i = 0; i < 26; i++){
cur = nd[x].son[i];
if (!mk[cur] && cur != 0){
output += val[cur];
dfs(cur);
output += '-';
}
}
for (int i = 0; i < 26; i++){
cur = nd[x].son[i];
if (mk[cur] && cur != 0){
output += val[cur];
dfs(cur);
output += '-';
}
}
}
int main(){
cin.tie(NULL);
ios_base::sync_with_stdio(false);
cin >> m;
string max_size;
for (int i = 1; i <= m; i++){
string s;
cin >> s;
add(s);
if (max_size.size() < s.size()){
max_size = s;
}
}
mark(max_size);
dfs(0);
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... |