# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
525132 | perchuts | Poklon (COCI17_poklon7) | C++17 | 206 ms | 64584 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define maxn (int)(1e5+51)
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define ll long long
#define pb push_back
#define ull unsigned long long
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define inf 2000000001
#define mod 1000000007 //998244353
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
struct node{
ll l, r;
}nd;
vector<node>g;
ll dfs(int x){
int changel=0,changer=0;
if(g[x].l>0)g[x].l = dfs(g[x].l),changel++;
else g[x].l*=-1LL;
if(g[x].r>0)g[x].r = dfs(g[x].r),changer++;
else g[x].r*=-1LL;
ll dif = abs(g[x].l - g[x].r);
if((dif&1)&&changel+changer){
if(changel){
if(g[x].l>g[x].r)return g[x].l + g[x].r + dif;
else return g[x].l + g[x].r + dif + 2;
}else{
if(g[x].r>g[x].l)return g[x].l + g[x].r + dif;
else return g[x].l + g[x].r + dif + 2;
}
}
return g[x].r + g[x].l + dif;
}
int main(){_
int n;cin>>n;
g.resize(n+1);
for(int i=1;i<=n;i++){
ll l,r;cin>>g[i].l>>g[i].r;
}
ll ans = dfs(1);
vector<int>resp;
while(ans){
resp.pb(ans&1);
ans>>=1;
}
reverse(all(resp));
for(auto x:resp)cout<<x;
cout<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |