Submission #1297422

#TimeUsernameProblemLanguageResultExecution timeMemory
1297422baotoan655Cave (IOI13_cave)C++20
100 / 100
178 ms516 KiB
#include <bits/stdc++.h>
#define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
using namespace std;

#include "cave.h"

const int N = 5005;
int S[N], D[N];
bool vs[N];

void change(int s, int e) {
    for(int i = s; i <= e; i++) {
        if(!vs[i]) S[i] ^= 1;
    }
}

int find(int pos, int n) {
    int s = 0, e = n - 1;
    if(tryCombination(S) != pos) change(0, n - 1);
    while (s != e) {
        int m = (s + e) / 2;
        change(s, m);
        int t = tryCombination(S);
        change(s, m);
        if(pos != t) e = m;
        else s = m + 1;
    }
    return s;
}

void exploreCave(int n) {
    for (int i = 0; i < n; i++) {
        int pos = find(i, n);
        D[pos] = i;
        vs[pos] = 1;
        S[pos] ^= 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...