답안 #577889

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
577889 2022-06-15T11:42:05 Z NintsiChkhaidze Poklon (COCI17_poklon7) C++14
114 / 120
574 ms 262144 KB
#include <bits/stdc++.h>
//#include <vector>
//#include <iostream>
#define ll long long
#define pb push_back
#define s second
#define f first

using namespace std;
const int N = 1000005;
int a[N],b[N];

vector<int> bin(int x){
    vector<int> str; str.clear();
    bool z=0;
    for (int j=29;j>=0;j--){
        if((1LL<<j)&x) str.pb(1),z=1;
        else if (z) str.pb(0);
    }
    return str;
}
vector <int> comp(vector <int> a,vector <int> b){
    if (a.size() > b.size()) return a;
    if (a.size() < b.size()) return b;

    for (int i=0;i<a.size();i++){
        if (a[i] > b[i]) return a;
        if (a[i] < b[i]) return b;
    }
    return a;
}
vector <int> dfs(int x){
    vector<int> mx;
    if (a[x] < 0 && b[x] < 0) {
        mx = bin(max(-a[x],-b[x]));
    }else if (a[x] < 0){
        mx = bin(-a[x]);
    }else if (b[x]<0){
        mx = bin(-b[x]);
    }else{
        mx= comp(dfs(a[x]),dfs(b[x]));
        mx.pb(0);
        return mx;
    }

    if (a[x] > 0)
        mx = comp(mx,dfs(a[x]));

    if (b[x] > 0)
        mx = comp(mx,dfs(b[x]));

    mx.pb(0);
    return mx;
}
signed main() {
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int n;
    cin>>n;

    for(int i = 1; i <= n; i++)
        cin>>a[i]>>b[i];

    vector<int> res = dfs(1);
    bool z=0;
    for (int i=0;i<res.size();i++){
        if (res[i] == 1) z=1;
        if(z) cout<<res[i];
    }
}

Compilation message

poklon.cpp: In function 'std::vector<int> comp(std::vector<int>, std::vector<int>)':
poklon.cpp:26:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (int i=0;i<a.size();i++){
      |                  ~^~~~~~~~~
poklon.cpp: In function 'int main()':
poklon.cpp:65:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     for (int i=0;i<res.size();i++){
      |                  ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 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 7 ms 2132 KB Output is correct
12 Correct 10 ms 1684 KB Output is correct
13 Correct 32 ms 9888 KB Output is correct
14 Correct 60 ms 20248 KB Output is correct
15 Correct 47 ms 1120 KB Output is correct
16 Correct 207 ms 48948 KB Output is correct
17 Correct 452 ms 101160 KB Output is correct
18 Correct 454 ms 117220 KB Output is correct
19 Correct 574 ms 73948 KB Output is correct
20 Runtime error 531 ms 262144 KB Execution killed with signal 9