# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
735273 | 2023-05-03T19:47:58 Z | PanosPask | Type Printer (IOI08_printer) | C++14 | 325 ms | 54144 KB |
#include <bits/stdc++.h> using namespace std; int n; queue<char> ans; struct Trie { int maxlength = 0; int size = 0; char maxkid = '\0'; bool isword = false; map<char, Trie> kids; void insert(const string& word, int pos) { size++; if (pos == word.size()) isword = true; else kids[word[pos]].insert(word, pos + 1); if (word.size() - pos + 1 > maxlength) { maxlength = word.size() - pos + 1; maxkid = word[pos]; } } void calculate_answer(bool leaveit) { if (isword) ans.push('P'); for (auto kid : kids) if (kid.first != maxkid && kid.second.size) { ans.push(kid.first); kid.second.calculate_answer(false); ans.push('-'); } if (maxkid != '\0') { ans.push(maxkid); kids[maxkid].calculate_answer(leaveit); if (!leaveit) ans.push('-'); } } }; Trie t; int main(void) { ios::sync_with_stdio(false); cin >> n; string s; for (int i = 0; i < n; i++) { cin >> s; t.insert(s, 0); } t.calculate_answer(true); cout << ans.size() << '\n'; while(!ans.empty()) { cout << ans.front() << '\n'; ans.pop(); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 320 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 2 ms | 724 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 1108 KB | Output is correct |
2 | Correct | 4 ms | 1364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 3324 KB | Output is correct |
2 | Correct | 32 ms | 6856 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 37 ms | 8012 KB | Output is correct |
2 | Correct | 14 ms | 2008 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 128 ms | 19692 KB | Output is correct |
2 | Correct | 325 ms | 45884 KB | Output is correct |
3 | Correct | 162 ms | 26108 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 77 ms | 15548 KB | Output is correct |
2 | Correct | 295 ms | 54144 KB | Output is correct |
3 | Correct | 155 ms | 28220 KB | Output is correct |
4 | Correct | 297 ms | 50512 KB | Output is correct |