# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
935210 | 2024-02-28T20:07:53 Z | asdasdqwer | Type Printer (IOI08_printer) | C++14 | 380 ms | 225520 KB |
#include <bits/stdc++.h> using namespace std; struct Node { char l; map<char,int> child; }; vector<Node> trie(500001); int last = 1; void insWord(string &s) { int idx = 0; for (auto &x:s) { if (trie[idx].child[x-'a'] == 0) { trie[idx].child[x-'a'] = last; trie[last].l = x; last++; } idx = trie[idx].child[x-'a']; } } struct Operation { char chr; bool isPrint = false; bool isBack = false; }; vector<Operation> out; void traversal(int index) { bool foundOne = false; for (int i=0;i<26;i++) { if (trie[index].child[i] == 0) continue; Operation op;op.chr = i + 'a'; out.push_back(op); traversal(trie[index].child[i]); op.isBack = true; out.push_back(op); foundOne = true; } if (!foundOne) { Operation op;op.isPrint=true; out.push_back(op); } } signed main() { ios::sync_with_stdio(false); cin.tie(0); int n;cin>>n; vector<string> v(n); for (auto &x:v)cin>>x; trie[0].l = ' '; for (auto x:v) { insWord(x); } // it's always optimal to stop at the word with the largest length string s = ""; for (auto &x:v) { if (x.size() > s.size()) { s = x; } } int index = 0; for (auto &x:s) { int nxt; for (int i=0;i<26;i++) { if (trie[index].child[i] != 0 && i != (x-'a')) { Operation op;op.chr=i+'a'; out.push_back(op); traversal(trie[index].child[i]); op.isBack = true; out.push_back(op); } else if (i == (x-'a')) { nxt = trie[index].child[i]; } } Operation op;op.chr=x; out.push_back(op); index = nxt; } Operation op;op.isPrint=true; out.push_back(op); cout<<out.size()<<"\n"; for (auto &x:out) { if (x.isBack) { cout<<"-\n"; } else if (x.isPrint) { cout<<"P\n"; } else { cout<<x.chr<<"\n"; } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 27740 KB | Output is correct |
2 | Correct | 6 ms | 27864 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 27740 KB | Output is correct |
2 | Correct | 7 ms | 27740 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 27740 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 27868 KB | Output is correct |
2 | Incorrect | 8 ms | 27740 KB | didn't print every word |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 28508 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 20 ms | 35932 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 69 ms | 58452 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 159 ms | 105992 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 380 ms | 225520 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 313 ms | 181776 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |