# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
604723 | neki | Type Printer (IOI08_printer) | C++14 | 170 ms | 57940 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>
#define ll long long
#define vc vector
using namespace std;
const ll mn =500100;
ll cnt=0;
map<char, ll> tr[mn];
ll konci[mn];
void add(string s){
ll cur=0;
for(auto v: s){
if(tr[cur].find(v)==tr[cur].end()) tr[cur][v]=++cnt;
cur=tr[cur][v];
}
assert(cnt<mn);
assert(cur<mn);
++konci[cur];
}
vc<char> ans;
void dfs(ll u, string& izogni, ll ind){
for(ll i=0;i<konci[u];++i) ans.push_back('P');
for(auto v: tr[u]){
if(ind<izogni.size() and v.first==izogni[ind]) continue;
ans.push_back(v.first);
dfs(v.second, izogni, ind+1);
ans.push_back('-');
}
if(ind<izogni.size() and tr[u].find(izogni[ind])!=tr[u].end()){
ans.push_back(izogni[ind]);
dfs(tr[u][izogni[ind]], izogni, ind+1);
ans.push_back('-');
}
}
int main() {
ll n;cin >> n;
string l="";
for(ll i=0;i<n;++i){
string s;cin >> s;
if(l.size()<s.size()) l=s;
add(s);
}
dfs(0, l, 0);
while(ans.back()=='-') ans.pop_back();
cout << ans.size()<<'\n';
for(auto v: ans) cout << v << '\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... |