# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
880498 | 2023-11-29T14:38:00 Z | StefanL2005 | Type Printer (IOI08_printer) | C++14 | 143 ms | 119364 KB |
#include <bits/stdc++.h> using namespace std; #define CH (*p - 'a') int nr = 0; struct Trie { int down, word; Trie *path; vector<Trie*> fii; Trie() { down = word = 0; path = 0; fii = vector<Trie*> (26, 0); } }; Trie *Root = new Trie; void insert(Trie *Nod, char *p) { if (*p == '\0') { Nod->word++; return; } if (Nod->fii[CH] == NULL) { Nod->fii[CH] = new Trie; nr++; } insert(Nod->fii[CH], p + 1); if (Nod->fii[CH]->down + 1 > Nod->down) { Nod->down = Nod->fii[CH]->down + 1; Nod->path = Nod->fii[CH]; } } void easy_search(Trie *Nod) { while (Nod->word > 0) { cout<< "P\n"; Nod->word--; } for (int i = 0; i < 26; i++) if (Nod->fii[i] != NULL) { cout<< (char) (i + 'a') << "\n"; easy_search(Nod->fii[i]); cout<< "-\n"; } } int show_longest(Trie *Nod, int k) { if (Nod->path == NULL) return k; return show_longest(Nod->path, k + 1); } void complex_search(Trie *Nod) { while (Nod->word > 0) { cout<< "P\n"; Nod->word--; } if (Nod->path == NULL) return; char let; for (int i = 0; i < 26; i++) { if (Nod->fii[i] == NULL) continue; if (Nod->fii[i] == Nod->path) { let = (char) (i + 'a'); continue; } cout<< (char) (i + 'a') << "\n"; easy_search(Nod->fii[i]); cout<< "-\n"; } cout<< let << "\n"; complex_search(Nod->path); } int main() { int N; cin>> N; for (int i = 0; i < N; i++) { string w; cin>> w; insert(Root, &w[0]); } cout<< (nr - Root->down) * 2 + Root->down + N << "\n"; complex_search(Root); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 432 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 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 | 800 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 | 1 ms | 1372 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2140 KB | Output is correct |
2 | Correct | 3 ms | 2652 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 7004 KB | Output is correct |
2 | Correct | 17 ms | 14936 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 17500 KB | Output is correct |
2 | Correct | 9 ms | 3932 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 53 ms | 43744 KB | Output is correct |
2 | Correct | 115 ms | 100088 KB | Output is correct |
3 | Correct | 64 ms | 51444 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 34132 KB | Output is correct |
2 | Correct | 143 ms | 119364 KB | Output is correct |
3 | Correct | 72 ms | 58560 KB | Output is correct |
4 | Correct | 115 ms | 112500 KB | Output is correct |