# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
198778 | 2020-01-27T15:28:25 Z | arnold518 | Type Printer (IOI08_printer) | C++14 | 132 ms | 41716 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 25000; int N; string S; vector<char> ans; struct Node { int dep; Node *chd[30]; Node() { int i, j; for(i=0; i<26; i++) chd[i]=NULL; } void update(string &S) { if(S.empty()) return; char c=S.back(); S.pop_back(); if(chd[c-'a']==NULL) chd[c-'a']=new Node(); chd[c-'a']->update(S); } void calc() { int i, j; for(i=0; i<26; i++) { if(chd[i]==NULL) continue; chd[i]->calc(); dep=max(dep, chd[i]->dep+1); } } void dfs() { int i, j; int cnt=0; vector<int> V; for(i=0; i<26; i++) { if(chd[i]==NULL) continue; V.push_back(i); } sort(V.begin(), V.end(), [&](const int &p, const int &q) { return chd[p]->dep<chd[q]->dep; }); for(auto i : V) { cnt++; ans.push_back(i+'a'); chd[i]->dfs(); ans.push_back('-'); } if(cnt==0) ans.push_back('P'); } }; Node *root=new Node(); int main() { int i, j; cin>>N; for(i=1; i<=N; i++) { cin>>S; reverse(S.begin(), S.end()); root->update(S); } root->calc(); root->dfs(); while(!ans.empty() && ans.back()=='-') ans.pop_back(); printf("%d\n", ans.size()); for(auto it : ans) printf("%c\n", it); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 6 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 6 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 376 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Incorrect | 6 ms | 376 KB | didn't print every word |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 504 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 10 ms | 2040 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 22 ms | 6776 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 55 ms | 16760 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 132 ms | 41716 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 107 ms | 32624 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |