# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1010646 | 2024-06-29T09:03:39 Z | Muaath_5 | Type Printer (IOI08_printer) | C++17 | 187 ms | 106432 KB |
#include <bits/stdc++.h> #define ll long long const int N = 5001, MOD = 1e9+7; using namespace std; struct trie { char ch = 0; bool end = false; trie* chrs[26]; int mxdep = 0; }; int n; trie* root = new trie(); void add(string& x) { trie* cur = root; for (int i = 0; i < x.size(); i++) { if (!cur->chrs[x[i] - 'a']) cur->chrs[x[i] - 'a'] = new trie(); cur = cur->chrs[x[i] - 'a']; cur->ch = x[i]; } cur->end = true; } void dfs(trie* cur) { cur->mxdep = 1; for (trie* c : cur->chrs) { if (c) { dfs(c); cur->mxdep = max(cur->mxdep, c->mxdep+1); } } } int cnt = 0; vector<char> sol; void dfs2(trie* cur) { if (cur == nullptr) return; sort(cur->chrs, cur->chrs+26, [](trie* x, trie* y){ return (x ? x->mxdep : 0) < (y ? y->mxdep : 0); }); if (cur->ch != 0) sol.push_back(cur->ch); if (cur->end) { sol.push_back('P'); cnt++; if (cnt == n) { cout << sol.size() << '\n'; for (char c : sol) cout << c << '\n'; exit(0); } } for (int i = 0; i < 26; i++) { if (cur->chrs[i]) { dfs2(cur->chrs[i]); } } sol.push_back('-'); } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { string w; cin >> w; add(w); } dfs(root); dfs2(root); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 1116 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1884 KB | Output is correct |
2 | Correct | 4 ms | 2396 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 6492 KB | Output is correct |
2 | Correct | 25 ms | 13404 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 15828 KB | Output is correct |
2 | Correct | 8 ms | 3672 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 61 ms | 39116 KB | Output is correct |
2 | Correct | 132 ms | 89544 KB | Output is correct |
3 | Correct | 67 ms | 46284 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 51 ms | 30728 KB | Output is correct |
2 | Correct | 187 ms | 106432 KB | Output is correct |
3 | Correct | 101 ms | 52472 KB | Output is correct |
4 | Correct | 162 ms | 100424 KB | Output is correct |