# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
819014 | Sir_Ahmed_Imran | Type Printer (IOI08_printer) | C++17 | 110 ms | 98548 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.
///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define li long int
#define ld long double
#define append push_back
#define add insert
#define nl "\n"
#define ff first
#define ss second
#define pii pair<int,int>
#define pic pair<int,char>
#define all(x) (x).begin(),(x).end()
#define sum(a) accumulate(all(a),0)
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL)
#define terminator main
#define MAXN 100001
class TrieNode {
public:
int z;
bool prt;
TrieNode* nxt[26];
TrieNode(){
for(int i=prt=z=0;i<26;i++)
nxt[i]=NULL;
}
};
class Trie{
public:
TrieNode* root;
int siz;
Trie(){
siz=0;
root=new TrieNode();
}
void insert(string a){
int m;
TrieNode* x=root;
for(int i=0;i<a.size();i++){
m=a[i]-'a';
if(!x->nxt[m]){
siz++;
x->nxt[m]=new TrieNode();
}
x=x->nxt[m];
if(a.size()>x->z)
x->z=a.size();
}
x->prt=1;
}
void dfs(TrieNode* x){
vector<pii> v;
for(int i=0;i<26;i++)
if(x->nxt[i])
v.append({x->nxt[i]->z,i});
sort(all(v));
for(auto& i:v){
siz--;
cout<<char(i.ss+'a')<<nl;
if(x->nxt[i.ss]->prt){
siz--;
cout<<'P'<<nl;
}
dfs(x->nxt[i.ss]);
if(siz>0) cout<<'-'<<nl;
siz--;
}
}
};
void solve(){
string a;
int n,m,o,p,q;
Trie x;
cin>>n;
for(int i=m=0;i<n;i++){
cin>>a;
x.insert(a);
if(a.size()>m)
m=a.size();
}
x.siz=x.siz*2+n-m;
cout<<x.siz<<nl;
x.dfs(x.root);
}
int terminator(){
L0TA;
solve();
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... |