제출 #1239506

#제출 시각아이디문제언어결과실행 시간메모리
1239506AmaarsaaPoklon (COCI17_poklon7)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; using ll =int ; const ll N = 1e6 + 2; ll depth[N] = {0}; ll lef[N], rig[N]; string w[N]; string To_Bin(ll x) { ll i, r; string str = ""; for (i = 30; i >= 0; i --) { r = 1<<i; if ( x >= r) { x -= r; str = str + "1"; } else str = str + "0"; } r = 0; while ( r < str.size() && str[r] == '0') r ++; str = str.substr(r, str.size() - r); return str; } string add_one(string str) { ll r = str.size() - 1; while ( r >= 0 && str[r] == '1') { r --; } string str1 = str.substr(0, r + 1); if ( str1.size() == 0) str1 = "1"; else str1[str1.size() - 1] = '1'; str1 = str1 + string(str.size()- r - 1, '0'); return str1; } string Unite(string l, ll l_a, string r, ll r_a) { if (l_a < r_a) { swap(l_a, r_a); swap(l, r); } string new_l, new_r; ll is_zero = 1; for (ll i = max(0ll, ll(r.size() - l_a)); i < r.size(); i ++) { if ( r[i] == '1') is_zero = 0; } l = l.substr(0, l.size() - l_a); r = r.substr(0, max(0ll, ll(r.size() - l_a))); if (r.size() == 0) r = "0"; if ( is_zero == 0) r = add_one(r); string str; if ( r.size() > l.size()) str = r; else { if ( l.size() > r.size()) str = l; else str= max(l, r); } str = str + string(l_a + 1, '0'); return str; } void Find(ll x) { string lef_w, rig_w; ll lef_add, rig_add; if ( lef[x] < 0) { lef_w = To_Bin(-lef[x]); lef_add = 0; } else { Find(lef[x]); lef_w = w[lef[x]]; lef_add = depth[lef[x]]; } if ( rig[x] < 0) { rig_w = To_Bin(-rig[x]); rig_add = 0; } else { Find(rig[x]); rig_w = w[rig[x]]; rig_add = depth[rig[x]]; } depth[x] = max(lef_add, rig_add); w[x] = Unite(lef_w, lef_add, rig_w, rig_add); // cout << x << " " << w[x] << endl; } int main() { ll n, m, r, s, x, i, y; cin >> n; for (i = 1; i <= n; i ++){ cin >> lef[i] >> rig[i]; } // cout << "HI" <<endl; Find(1); cout << w[1] << endl; }

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

poklon.cpp: In function 'std::string Unite(std::string, ll, std::string, ll)':
poklon.cpp:47:21: error: no matching function for call to 'max(long long int, ll)'
   47 |      for (ll i = max(0ll, ll(r.size() - l_a)); i < r.size(); i ++) {
      |                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from poklon.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
poklon.cpp:47:21: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'll' {aka 'int'})
   47 |      for (ll i = max(0ll, ll(r.size() - l_a)); i < r.size(); i ++) {
      |                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from poklon.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
poklon.cpp:47:21: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'll' {aka 'int'})
   47 |      for (ll i = max(0ll, ll(r.size() - l_a)); i < r.size(); i ++) {
      |                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from poklon.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3461:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3461 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3461:5: note:   template argument deduction/substitution failed:
poklon.cpp:47:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   47 |      for (ll i = max(0ll, ll(r.size() - l_a)); i < r.size(); i ++) {
      |                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from poklon.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3467:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3467 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3467:5: note:   template argument deduction/substitution failed:
poklon.cpp:47:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   47 |      for (ll i = max(0ll, ll(r.size() - l_a)); i < r.size(); i ++) {
      |                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
poklon.cpp:51:25: error: no matching function for call to 'max(long long int, ll)'
   51 |      r = r.substr(0, max(0ll, ll(r.size() - l_a)));
      |                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from poklon.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
poklon.cpp:51:25: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'll' {aka 'int'})
   51 |      r = r.substr(0, max(0ll, ll(r.size() - l_a)));
      |                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from poklon.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
poklon.cpp:51:25: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'll' {aka 'int'})
   51 |      r = r.substr(0, max(0ll, ll(r.size() - l_a)));
      |                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from poklon.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3461:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3461 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3461:5: note:   template argument deduction/substitution failed:
poklon.cpp:51:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   51 |      r = r.substr(0, max(0ll, ll(r.size() - l_a)));
      |                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from poklon.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3467:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3467 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3467:5: note:   template argument deduction/substitution failed:
poklon.cpp:51:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   51 |      r = r.substr(0, max(0ll, ll(r.size() - l_a)));
      |                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~~