# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
499087 | Nartifact | Type Printer (IOI08_printer) | C++14 | 141 ms | 99628 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 int long long
#define rep(i,b) for (int i=0;i<b;++i)
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define pii pair <int,int>
#define piii pair <int, pii>
#define fi first
#define se second
#define two(x) (1ll << x)
#define getbit(i, x) (x >> i & 1ll)
#define onbit(i, x) (x|(1ll << i))
#define offbit(i, x) (x & ~(1ll << i))
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
const int N = 25025;
int n;
string sta;
vector <char> ans;
struct node
{
node* child[26];
bool eos, ok;
node () {
forinc(i,0,25) child[i] = nullptr;
eos = ok = 0;
}
};
struct Trie
{
node* root;
Trie () {root = new node();}
void add (const string& s, const bool& type) {
node* tmp = root;
for (char c : s) {
int pos = c - 'a';
if(!tmp->child[pos]) tmp->child[pos] = new node();
tmp = tmp->child[pos];
tmp->ok = type;
}
tmp->eos = 1;
tmp->ok = type;
}
void solve (node* tmp) {
if(tmp->eos) ans.eb('P');
int check = -1;
forinc(i,0,25) if(tmp->child[i]) {
node* nxt = tmp->child[i];
if(nxt->ok) check = i;
else {
ans.eb(i + 'a');
solve(nxt);
ans.eb('-');
}
}
if(check != -1){
ans.eb(check + 'a');
solve(tmp->child[check]);
}
}
} trie;
void read ()
{
cin >> n;
string s;
forinc(i,1,n) {
cin >> s;
trie.add(s, 0);
if(s.size() > sta.size()) sta = s;
}
trie.add(sta, 1);
trie.solve(trie.root);
cout << ans.size() << '\n';
for (char i : ans) cout << i << '\n';
}
main ()
{
#define task ""
cin.tie(0) -> sync_with_stdio(0);
if(fopen (task ".inp", "r")) {
freopen (task ".inp", "r", stdin);
freopen (task ".out", "w", stdout);
}
read();
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... |