Submission #1239522

#TimeUsernameProblemLanguageResultExecution timeMemory
1239522AmaarsaaPoklon (COCI17_poklon)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;
using ll =long long ;
const ll N = 1e6 + 2;

ll lef[N], rig[N];


string To_Bin(ll x) {
    ll i, r;
    string str = "";
    for (i = 31; 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);
     }
     ll is_zero = 1;
     
//     for (ll i = max(int(0), int(r.size() - (l_a - r_a ))); i < r.size(); i ++) {
//     	if ( r[i] == '1') is_zero = 0;
//	 }
	 if ( max(int(0), ll(r.size() -(l_a - r_a))) == 0) r = "0";
    else r = r.substr(0, max(int(0), ll(r.size() -(l_a - r_a))));
//	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);
	}
	return str;
}

pair < string, ll > 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 {
    	pair < string, ll > R = Find(lef[x]);
        lef_w = R.first;
        lef_add =R.second;
    }
    if ( rig[x] < 0) {
        rig_w = To_Bin(-rig[x]);
        rig_add = 0;
    }
    else {
        pair <string, ll > R = Find(rig[x]);
        rig_w = R.first;
        rig_add =R.second;
    }
    pair < string, ll > P;
    P = make_pair(Unite(lef_w, lef_add, rig_w, rig_add), max(lef_add, rig_add) + 1);
    return P;
}


int main() {
	ios::sync_with_stdio();
	cin.tie(0);
	cout.tie(0);
    ll n, m, r, s, x, i, y;

    cin >> n;

    for (i = 1; i <= n; i ++){
        cin >> lef[i] >> rig[i];
    }
  //  cout << "HI" <<endl;
  pair < string, ll > P = Find(1);
   string ans = P.first;
   ll depth = P.second;
//   if ( w[1].size() > 33) {
  // 	while(1);
   //}
   cout << ans;
   for (i =0 ; i < depth; i ++) cout << '0';
   cout<< endl;
}

Compilation message (stderr)

poklon.cpp: In function 'std::string Unite(std::string, ll, std::string, ll)':
poklon.cpp:47:18: error: no matching function for call to 'max(int, ll)'
   47 |          if ( max(int(0), ll(r.size() -(l_a - r_a))) == 0) r = "0";
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:18: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   47 |          if ( max(int(0), ll(r.size() -(l_a - r_a))) == 0) r = "0";
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:18: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   47 |          if ( max(int(0), ll(r.size() -(l_a - r_a))) == 0) r = "0";
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   47 |          if ( max(int(0), ll(r.size() -(l_a - r_a))) == 0) r = "0";
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   47 |          if ( max(int(0), ll(r.size() -(l_a - r_a))) == 0) r = "0";
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
poklon.cpp:48:29: error: no matching function for call to 'max(int, ll)'
   48 |     else r = r.substr(0, max(int(0), ll(r.size() -(l_a - r_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:48:29: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   48 |     else r = r.substr(0, max(int(0), ll(r.size() -(l_a - r_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:48:29: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   48 |     else r = r.substr(0, max(int(0), ll(r.size() -(l_a - r_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:48:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   48 |     else r = r.substr(0, max(int(0), ll(r.size() -(l_a - r_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:48:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   48 |     else r = r.substr(0, max(int(0), ll(r.size() -(l_a - r_a))));
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~