Submission #432097

#TimeUsernameProblemLanguageResultExecution timeMemory
432097MilosMilutinovicCave (IOI13_cave)C++14
0 / 100
2 ms716 KiB
#include "cave.h"
#include <bits/stdc++.h>
using namespace std;

int tryCombination(int S[]);

void answer(int S[], int D[]);

void exploreCave(int N) {
    int combination[N];
    vector<bool> locked(N, false);

    for (int i = 0; i < N; i++) {
        vector<int> positions;
        for (int j = 0; j < N; j++)
            if (!locked[j])
                positions.push_back(j);

        int current = tryCombination(combination);
        bool need_diff = (current == -1 || current > i);

        int bot = 0, top = (int) positions.size() - 1, pos = -1;
        while (bot <= top) {
            int mid = bot + top >> 1;
            for (int j = 0; j < mid; j++)
                combination[j] ^= 1;
            if (need_diff)
                combination[mid] ^= 1;

            if (tryCombination(combination) == i)
                pos = mid, bot = mid + 1;
            else
                top = mid - 1;

            for (int j = 0; j < mid; j++)
                combination[j] ^= 1;
            if (need_diff)
                combination[mid] ^= 1;
        }

        assert(pos != -1);

        locked[pos] = true;
        combination[pos] ^= 1;
    }
}

Compilation message (stderr)

cave.cpp: In function 'void exploreCave(int)':
cave.cpp:24:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   24 |             int mid = bot + top >> 1;
      |                       ~~~~^~~~~
#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...