# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
387396 | 2021-04-08T10:28:32 Z | stefantaga | Type Printer (IOI08_printer) | C++14 | 215 ms | 106656 KB |
#include <bits/stdc++.h> using namespace std; struct trie { int nr,marime; trie *v[28]; trie () { int j; nr=0; marime=0; for (j=0;j<=26;j++) { v[j]=nullptr; } } } *tree = new trie ; void adauga (trie *tree, char *s) { if (*s==0) { tree->nr++; return; } int loc=(*s-'a'); if (tree->v[loc]==nullptr) { tree->v[loc]=new trie; } adauga(tree->v[loc],s+1); } vector <char> op; void dfs1(trie *tree) { int j; tree->marime=1; for (j=0;j<=26;j++) { if (tree->v[j]!=nullptr) { dfs1(tree->v[j]); tree->marime=max(tree->marime,tree->v[j]->marime+1); } } } void dfs2(trie *tree) { int j; for (j=1;j<=tree->nr;j++) { op.push_back('P'); } vector <pair <int,int> > val; for (j=0;j<=26;j++) { if (tree->v[j]!=nullptr) { val.push_back({tree->v[j]->marime,j}); } } sort (val.begin(),val.end()); for (j=0;j<val.size();j++) { op.push_back((char)(val[j].second+97)); dfs2(tree->v[val[j].second]); } op.push_back('-'); } int n,i,j; char s[25]; int main() { ios_base :: sync_with_stdio(false); cin.tie(0); #ifdef HOME ifstream cin("date.in"); ofstream cout("date.out"); #endif // HOME cin>>n; for (i=1;i<=n;i++) { cin>>s; adauga(tree,s); } dfs1(tree); dfs2(tree); while (op.size()>0&&op[op.size()-1]=='-') { op.pop_back(); } cout<<op.size()<<'\n'; for (j=0;j<op.size();j++) { cout<<op[j]<<'\n'; } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 492 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 492 KB | Output is correct |
2 | Correct | 3 ms | 1260 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2028 KB | Output is correct |
2 | Correct | 5 ms | 2412 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 6380 KB | Output is correct |
2 | Correct | 28 ms | 13420 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 15848 KB | Output is correct |
2 | Correct | 11 ms | 3692 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 84 ms | 39268 KB | Output is correct |
2 | Correct | 181 ms | 89728 KB | Output is correct |
3 | Correct | 96 ms | 46180 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 70 ms | 30692 KB | Output is correct |
2 | Correct | 215 ms | 106656 KB | Output is correct |
3 | Correct | 107 ms | 52460 KB | Output is correct |
4 | Correct | 187 ms | 100584 KB | Output is correct |