제출 #328671

#제출 시각아이디문제언어결과실행 시간메모리
328671aris12345678Type Printer (IOI08_printer)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pi pair<int, int> #define fi first #define se second const int mxN = 1e5+5; const int mod = 1e9+7; const ll inf = 1e18; struct node { bool word; int depth; node *children[26]; node() { word = 0, depth = 0; for(int i = 0; i < 26; i++) children[i] = nullptr; } }; node *root = new node(); int n; string s[mxN]; vector<char> ans; // insert string s void add(string s) { node *cur = root; for(int i = 0; i < s.length(); i++) { cur->depth = max(cur->depth, s.length()); if(cur->children[s[i]-'a'] == nullptr) cur->children[s[i]-'a'] = new node(); cur = cur->children[s[i]-'a']; } cur->depth = max(cur->depth, s.length()); cur->word = 1; } // dfs in a trie starting from the root void dfs(node *u, int back) { if(u->word) ans.push_back('P'); // red vertice - end of the word int p = 0; node *x = nullptr; for(int i = 0; i < 26; i++) { node *v = u->children[i]; if(v == nullptr) continue; if(x == nullptr || v->depth > x->depth) { x = v; p = i; } if(v == x) continue; ans.push_back(i+'a'); dfs(v, 0); } if(x != nullptr) { ans.push_back(p+'a'); dfs(x, back); } if(!back) ans.push_back('-'); } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 0; i < n; i++) { cin >> s[i]; add(s[i]); } dfs(root, 1); cout << ans.size() << "\n"; for(char i : ans) cout << i << "\n"; return 0; }

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

printer.cpp: In function 'void add(std::string)':
printer.cpp:30:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i = 0; i < s.length(); i++) {
      |                    ~~^~~~~~~~~~~~
printer.cpp:31:48: error: no matching function for call to 'max(int&, std::__cxx11::basic_string<char>::size_type)'
   31 |         cur->depth = max(cur->depth, s.length());
      |                                                ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from printer.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:222:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  222 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:222:5: note:   template argument deduction/substitution failed:
printer.cpp:31:48: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'})
   31 |         cur->depth = max(cur->depth, s.length());
      |                                                ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from printer.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:268:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  268 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:268:5: note:   template argument deduction/substitution failed:
printer.cpp:31:48: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'})
   31 |         cur->depth = max(cur->depth, s.length());
      |                                                ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from printer.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3456:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3456 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
printer.cpp:31:48: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   31 |         cur->depth = max(cur->depth, s.length());
      |                                                ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from printer.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3462:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3462 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
printer.cpp:31:48: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   31 |         cur->depth = max(cur->depth, s.length());
      |                                                ^
printer.cpp:35:44: error: no matching function for call to 'max(int&, std::__cxx11::basic_string<char>::size_type)'
   35 |     cur->depth = max(cur->depth, s.length());
      |                                            ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from printer.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:222:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  222 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:222:5: note:   template argument deduction/substitution failed:
printer.cpp:35:44: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'})
   35 |     cur->depth = max(cur->depth, s.length());
      |                                            ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from printer.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:268:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  268 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:268:5: note:   template argument deduction/substitution failed:
printer.cpp:35:44: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'})
   35 |     cur->depth = max(cur->depth, s.length());
      |                                            ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from printer.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3456:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3456 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
printer.cpp:35:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   35 |     cur->depth = max(cur->depth, s.length());
      |                                            ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from printer.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3462:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3462 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
printer.cpp:35:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   35 |     cur->depth = max(cur->depth, s.length());
      |                                            ^