Submission #1202090

#TimeUsernameProblemLanguageResultExecution timeMemory
1202090totoroCave (IOI13_cave)C++20
100 / 100
121 ms532 KiB
#include "cave.h"

#include <iostream>
#include <vector>

void exploreCave(int N) {
    std::vector<int> matchesto(N);
    std::vector<int> fixed(N);
    for (int i = 0; i < N; ++i) {
        int lo = 0, hi = N - 1;
        std::vector<int> S(N);
        for (int j = 0; j < N; ++j) {
            if (fixed[j])
                S[j] = fixed[j] - 1;
            else
                S[j] = 1;
        }
        // for (int k : S) {
        //     std::cout << k << ' ';
        // }
        // std::cout << '\n';
        int last = (tryCombination(S.data()) == i);
        while (lo < hi) {
            int mid = (lo + hi) / 2;
            for (int j = lo; j <= mid; ++j) {
                if (fixed[j])
                    S[j] = fixed[j] - 1;
                else
                    S[j] ^= 1;
            }

            int now = (tryCombination(S.data()) == i);
            if (now == last)
                lo = mid + 1;
            else
                hi = mid;
            last = now;
        }
        matchesto[lo] = i;
        fixed[lo] = (S[lo] ^ last) + 1;
    }

    for (int& i : fixed) --i;

    answer(fixed.data(), matchesto.data());
}
#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...