# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
739605 | MODDI | Type Printer (IOI08_printer) | C++14 | 148 ms | 108360 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>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
template<class T> bool ckmax(T& a, const T& b){return a<b?a=b,1:0;}
int n;
vector<string> str;
struct trie{
trie* children[26]={};
int last = 69, mxd = -1;
bool leaf = false;
};
void trie_add(trie* root, string s){
trie* cur = root;
for(int i = 0; i < s.size(); i++){
int c = s[i] - 'a';
if(cur->children[c] == NULL)
cur->children[c] = new trie;
if(ckmax(cur->mxd, (int)s.size() - i -1))
cur-> last = c;
cur = cur->children[c];
}
cur->leaf = true;
}
vector<char> ans;
void dfs(trie* root){
if(root->leaf) ans.pb('P');
for(int i = 0; i < 26; i++){
if(root->children[i] != NULL && i != root->last){
ans.pb(char(i + 'a'));
dfs(root->children[i]);
}
}
if(root->last != 69){
ans.pb(char(root->last +'a'));
dfs(root->children[root->last]);
}
ans.pb('-');
}
int main(){
cin>>n;
str.resize(n);
for(int i = 0; i < n; i++)
cin>>str[i];
trie t;
for(auto i : str){
trie_add(&t, i);
}
dfs(&t);
while(ans.back() == '-') ans.pop_back();
cout<<ans.size()<<endl;
for(auto t : ans)
cout<<t<<'\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... |