Submission #1310710

#TimeUsernameProblemLanguageResultExecution timeMemory
1310710aleksandreCave (IOI13_cave)C++20
100 / 100
543 ms576 KiB
#include "cave.h"
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 5000005;
int n;
int fix[N];
int ind,ans[N],p[N],cnt[N];
void exploreCave(int N) {
    n = N;
    int v[n];
    for (int i = 0; i < n; i++) {
        v[i] = 0;
    }
    for (int i = 0; i < n; i++) {   
        for (int j = 0; j < n; j++) {
            if (!fix[j]) {
                v[j] = 0;
            }
        } 
        int c = tryCombination(v);
        int ok;
        if (c == i) {
            ok = 1;
        } else {
            ok = 0;
        }
        int l = 0; int r = n-1;
        while (l <= r) {
            int mid = (l+r)/2;
            for (int j = 0; j < n; j++) {
                if (fix[j]) continue;
                v[j] = 1 - ok; 
            }
            for (int j = 0; j <= mid; j++) {
                if (fix[j]) continue;
                v[j] = ok;
            }
            int m = tryCombination(v);
            if (m == -1 || m > i) {
                ind = mid;
                r = mid - 1;
            } else {
                l = mid + 1;

            }
            c = m;
        }
        ans[i] = ind;
        fix[ind] = 1;
        p[ind] = ok;
        v[ind] = ok;
    }
    int S[N],D[N];
    for (int i = 0; i < n; i++) {
        S[i] = v[i];
        D[ans[i]] = i; 
    }
    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...