답안 #867600

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
867600 2023-10-28T21:46:04 Z bibinm popa (BOI18_popa) C++17
0 / 100
9 ms 856 KB
#include "popa.h"
#include <vector>

using namespace std;

bool is_anc(int x, int y){
    // gcd(S_x, S_x) == gcd(S_x, S_{x+1}) => S_x | S_{x+1} => x+1 is an ancestor
    return query(x, x, x, y);
}

int solve(int n, int* left, int* right){
    for(int i = 0; i < n; i += 1) left[i] = right[i] = -1;

    vector<int> down_right;
    down_right.push_back(0);

    int cur = 1;
    while(cur < n){
        while(cur < n and !is_anc(down_right.back(), cur)){
            down_right.push_back(cur);
            cur += 1;
        }

        if(cur == n) break;

        int more_down = down_right.back(); down_right.pop_back();
        while(down_right.size() > 0 and is_anc(down_right.back(), cur)){
            right[down_right.back()] = more_down;
            more_down = down_right.back(); down_right.pop_back();
        }

        left[cur] = more_down;

        down_right.push_back(cur);

        cur += 1;
    }


    int more_down = down_right.back(); down_right.pop_back();
    while(down_right.size() > 0){
        right[down_right.back()] = more_down;
        more_down = down_right.back(); down_right.pop_back();
    }

    return more_down;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 428 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 416 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 856 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -