# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
492753 | erik_kl1 | Type Printer (IOI08_printer) | C++11 | 120 ms | 102168 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 F0R(i, n) for(int i = 0; i < (n); i++)
using namespace std;
ostringstream os;
struct node {
int term_cnt;
bool marked;
node *nex[26];
node() {
term_cnt = 0;
marked = 0;
F0R(i,26)
nex[i] = NULL;
}
};
struct trie {
node rt;
void insert(string s) {
node *cur = &rt;
F0R(i,s.size()) {
if(cur->nex[s[i]-'a'] == NULL)
cur->nex[s[i]-'a'] = new node();
cur = cur->nex[s[i]-'a'];
}
cur->term_cnt++;
}
void mark(string s) {
node *cur = &rt;
F0R(i,s.size()) {
cur = cur->nex[s[i]-'a'];
cur->marked = 1;
}
}
}
t;
int dfs(node *v) {
int ret = v->term_cnt;
F0R(i,ret)
os << "P\n";
F0R(i,26) if(v->nex[i] != NULL && !v->nex[i]->marked) {
os << ((char) (i+'a')) << '\n';
ret += dfs(v->nex[i]);
os << "-\n";
ret += 2;
}
F0R(i,26) if(v->nex[i] != NULL && v->nex[i]->marked) {
os << ((char) (i+'a')) << '\n';
ret += dfs(v->nex[i]);
ret++;
}
return ret;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int N; cin >> N;
string longest = "";
F0R(i,N) {
string s; cin >> s;
t.insert(s);
if(s.size() > longest.size())
longest = s;
}
t.mark(longest);
cout << dfs(&t.rt) << '\n';
cout << os.str();
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... |