제출 #521592

#제출 시각아이디문제언어결과실행 시간메모리
521592vlad_TTType Printer (IOI08_printer)C++17
0 / 100
57 ms76448 KiB
#include <iostream> #include <cstring> const int SIGMA = 26; struct Trie { int words; Trie* children[SIGMA]; bool is_ancestor; Trie() { words = 0; is_ancestor = false; for (int i = 0; i < SIGMA; i++) { children[i] = NULL; } } }; void insert(Trie* root, char* S) { if (*S == '\0') { root->words++; } else { if (root->children[S[0] - 'a'] == NULL) { root->children[S[0] - 'a'] = new Trie(); } insert(root->children[S[0] - 'a'], S + 1); } } void stramosi(Trie* root, char* S) { if (*S != '\0') { root->children[S[0] - 'a']->is_ancestor = true; stramosi(root->children[S[0] - 'a'], S + 1); } } int answer = 0; int count(Trie* root) { answer += root->words; for (int i = 0; i < SIGMA; i++) { if (root->children[i] != NULL && root->children[i]->is_ancestor == false) { answer++; count(root->children[i]); answer++; } } for (int i = 0; i < SIGMA; i++) { if (root->children[i] != NULL && root->children[i]->is_ancestor == true) { answer++; count(root->children[i]); } } } void dfs(Trie* root) { for (int i = 1; i <= root->words; i++) { std::cout << "P\n"; } for (int i = 0; i < SIGMA; i++) { if (root->children[i] != NULL && root->children[i]->is_ancestor == false) { std::cout << char(i + 'a') << "\n"; dfs(root->children[i]); std::cout << "-\n"; } } for (int i = 0; i < SIGMA; i++) { if (root->children[i] != NULL && root->children[i]->is_ancestor == true) { std::cout << char(i + 'a') << "\n"; dfs(root->children[i]); } } } int main() { Trie root; char* S = new char[20 + 1]; char last[20 + 1]; int n, mx = 0; std::cin >> n; for (int i = 1; i <= n; i++) { std::cin >> S; if (strlen(S) > mx) { mx = strlen(S); for (int j = 0; S[j] != '\0'; j++) { last[j] = S[j]; } } insert(&root, S); } char c; c = std::cin.get(); if (c == ' ') { c = std::cin.get(); } stramosi(&root, last); count(&root); std::cout << answer << "\n"; dfs(&root); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

printer.cpp: In function 'int count(Trie*)':
printer.cpp:55:1: warning: no return statement in function returning non-void [-Wreturn-type]
   55 | }
      | ^
printer.cpp: In function 'int main()':
printer.cpp:84:19: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   84 |     if (strlen(S) > mx) {
      |         ~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...