Submission #788662

#TimeUsernameProblemLanguageResultExecution timeMemory
788662borisAngelovCave (IOI13_cave)C++17
0 / 100
2 ms956 KiB
#include "cave.h"
#include <bits/stdc++.h>

using namespace std;

const int maxn = 5005;

int n;

int ans[maxn];
int val[maxn];
int connection[maxn];

int guess[maxn];

void exploreCave(int N)
{
    n = N;

    vector<int> switches;

    for (int i = 0; i < n; ++i)
    {
        switches.push_back(i);
    }

    for (int i = 0; i < n; ++i)
    {
        int curr_code = 1;

        for (int j = 0; j < n; ++j)
        {
            guess[j] = 1;
        }

        if (tryCombination(guess) == i)
        {
            curr_code = 0;
        }

        int l = 0;
        int r = switches.size() - 1;

        while (l <= r)
        {
            int mid = (l + r) / 2;

            for (int j = 0; j < i; ++j)
            {
                guess[ans[j]] = val[ans[j]];
            }

            for (int j = 0; j <= mid; ++j)
            {
                guess[switches[j]] = curr_code;
            }

            if (tryCombination(guess) == i)
            {
                l = mid + 1;
            }
            else
            {
                r = mid - 1;
            }
        }

        ans[i] = switches[l];

        val[switches[l]] = curr_code;

        switches.erase(switches.begin() + l);
    }

    for (int i = 0; i < n; ++i)
    {
        connection[ans[i]] = i;
    }

    answer(val, connection);
}
#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...