Submission #1167769

#TimeUsernameProblemLanguageResultExecution timeMemory
1167769DedibeatCave (IOI13_cave)C++20
0 / 100
1 ms576 KiB
#include "cave.h"
#include<bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define put(x) cout << (x) << '\n'
using namespace std;
using ll = long long;
void solve(int l, int r, vector<int> pos, int S[], int D[], int N){
    if(l > r) return;
    if(l == r){
        if(tryCombination(S) == l) S[pos[0]] ^= 1;
        return;
    }
    for(int i : pos){
        S[i] = rand() % 2;
    }
    int pivot = tryCombination(S);
    if(pivot == -1){
        return;
    }
    vector<int> lo, hi;
    int s_pivot = -1;
    for(int i : pos){
        S[i] ^= 1;
        int res = tryCombination(S);
        if(res < pivot) lo.push_back(i);
        else if(res == pivot) hi.push_back(i);
        else s_pivot = i;
        S[i] ^= 1;
    }
    assert(s_pivot == -1);
    S[s_pivot] ^= 1;
    solve(l, pivot - 1, lo, S, D, N);
    solve(pivot + 1, r, hi, S, D, N);
}
void exploreCave(int N){
    srand(time(NULL));
    int S[N], D[N];
    vector<int> pos(N);
    for(int i = 0; i < N; i++) pos[i] = i;
    solve(0, N - 1, pos, S, D, N);
    for(int i = 0; i < N; i++){
        S[i] ^= 1;
        D[i] = tryCombination(S);
        S[i] ^= 1;
    }
    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...