# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
936842 | Irate | Type Printer (IOI08_printer) | C++14 | 83 ms | 55624 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;
struct Trie{
vector<vector<int>>trie;
vector<bool>isWord;
int nxt = 1, mxN = 5e5 + 5;
string S = "";
Trie(){
trie.resize(26);
for(int i = 0;i < 26;++i){
trie[i].resize(mxN);
}
isWord.resize(mxN);
}
void Insert(string &s){
int cur = 0;
for(int i = 0;i < s.size();++i){
if(trie[s[i] - 'a'][cur]){
cur = trie[s[i] - 'a'][cur];
}
else{
trie[s[i] - 'a'][cur] = nxt;
cur = nxt;
nxt++;
}
}
isWord[cur] = 1;
}
void Traverse(int cur, bool check, int indx, string &longest){
if(isWord[cur]){
S += 'P';
S += '\n';
}
for(int i = 0;i < 26;++i){
if(!check && indx < longest.size() && longest[indx] == char('a' + i))continue;
if(trie[i][cur]){
S += char('a' + i);
S += '\n';
Traverse(trie[i][cur], 1, 0, longest);
}
}
if(!check && indx < longest.size()){
S += longest[indx];
S += '\n';
Traverse(trie[longest[indx] - 'a'][cur], 0, indx + 1, longest);
}
S += '-';
S += '\n';
}
};
int main(){
// ios_base::sync_with_stdio(0);
// cin.tie(0);
int n;
cin >> n;
Trie tr;
int mx = 0;
string longest = "";
for(int i = 0;i < n;++i){
string s;
cin >> s;
if(s.size() > mx){
mx = s.size();
longest = s;
}
tr.Insert(s);
}
tr.Traverse(0, 0, 0, longest);
while(tr.S.back() == '-' || tr.S.back() == '\n')tr.S.pop_back();
cout << (tr.S.size() + 1) / 2 << "\n" << tr.S;
}
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... |