답안 #545221

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
545221 2022-04-04T03:56:54 Z AbdelmagedNour Poklon (COCI17_poklon7) C++17
120 / 120
255 ms 56048 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int N=1000005;
int n,L[N],R[N];
pair<int,int>res={0,0};
bool f(pair<int,int>a,pair<int,int>b){
    if(a.first==0)return 0;
    if(b.first==0)return 1;
    if(a.first>b.first)return !f(b,a);
    while(a.first<b.first&&a.second){
        a.first*=2;
        a.second--;
    }
    if(a.first>=b.first&&a.second>=b.second){
        return 1;
    }else return 0;
}
void dfs(int v,int dep=0){
    if(v<=0){
        pair<int,int>val={-v,dep};
        if(f(val,res))res=val;
        return;
    }
    dfs(L[v],dep+1);
    dfs(R[v],dep+1);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>L[i]>>R[i];
    dfs(1);
    string s="";
    while(res.first){
        s+=char('0'+(res.first&1));
        res.first/=2;
    }
    reverse(s.begin(),s.end());
    cout<<s;
    for(int i=0;i<res.second;i++)cout<<0;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 14 ms 1504 KB Output is correct
14 Correct 23 ms 2632 KB Output is correct
15 Correct 21 ms 1088 KB Output is correct
16 Correct 76 ms 6500 KB Output is correct
17 Correct 181 ms 13644 KB Output is correct
18 Correct 187 ms 15148 KB Output is correct
19 Correct 217 ms 12852 KB Output is correct
20 Correct 255 ms 56048 KB Output is correct