제출 #499100

#제출 시각아이디문제언어결과실행 시간메모리
499100rampuType Printer (IOI08_printer)C++14
100 / 100
94 ms77052 KiB
#include <iostream> #include <cstring> #include <algorithm> using namespace std; int n; struct node { bool w = false; bool l = false; int next[26]; }; node trie[700000]; int t = 0; int maxi; string word, larger; void insert(const string &word, bool p) { int node = 0; for (int i = 0; i < word.size(); i++) { int letter = (word[i] - 'a'); trie[node].next[letter] = trie[node].next[letter] ? trie[node].next[letter] : ++t; node = trie[node].next[letter]; trie[node].l = p; } trie[node].w = true; trie[node].l = p; } string ans; void dfs(int node) { if (trie[node].w) ans += "P"; int pending = -1, next_node; for (int i = 0; i < 26; i++) { if (trie[node].next[i]) { next_node = trie[node].next[i]; if (trie[next_node].l) { pending = i; continue; } ans.push_back(i + 'a'); dfs(next_node); ans += "-"; } } if (pending != -1) { ans.push_back(pending + 'a'); dfs(trie[node].next[pending]); } } int main() { ios_base :: sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> word; insert(word, 0); if (word.size() >= maxi) { maxi = word.size(); larger = word; } } insert(larger, 1); dfs(0); cout << ans.size() << '\n'; for(int i = 0; i < ans.size(); i++) cout << ans[i] << '\n'; return 0; }

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

printer.cpp: In function 'void insert(const string&, bool)':
printer.cpp:20:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int i = 0; i < word.size(); i++) {
      |                     ~~^~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:62:25: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   62 |         if (word.size() >= maxi) {
      |             ~~~~~~~~~~~~^~~~~~~
printer.cpp:70:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for(int i = 0; i < ans.size(); i++)
      |                    ~~^~~~~~~~~~~~
#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...