제출 #528235

#제출 시각아이디문제언어결과실행 시간메모리
528235happypotato동굴 (IOI13_cave)C++17
100 / 100
222 ms484 KiB
#include "cave.h"
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
void exploreCave(int n) {
    vector<int> bit;
    for (int i = 0; i < n; i++) bit.pb(i);
    int S[n], D[n];
    for (int i = 0; i < n; i++) S[i] = 0;
    for (int i = 0; i < n; i++) {
        int res = tryCombination(S);
        bool open = (res >= i + 1);
        if (res == -1) open = true;
        int lb = 0, rb = bit.size() - 1;
        while (lb < rb) {
            int mid = (lb + rb) >> 1;
            for (int j = lb; j <= mid; j++) S[bit[j]] ^= 1;
            int res2 = tryCombination(S);
            bool open2 = (res2 >= i + 1);
            if (res2 == -1) open2 = true;
            for (int j = lb; j <= mid; j++) S[bit[j]] ^= 1;
            if (open == open2) lb = mid + 1;
            else rb = mid;
        }
        D[bit[lb]] = i;
        if (!open) S[bit[lb]] ^= 1;
        bit.erase(bit.begin() + lb);
    }
    answer(S, D);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...