Submission #563254

# Submission time Handle Problem Language Result Execution time Memory
563254 2022-05-16T15:36:15 Z imtiyazrasool92 Cave (IOI13_cave) C++17
0 / 100
96 ms 424 KB
#include "cave.h"
#include<set>
#include<vector>
#include<algorithm>
#include<numeric>
#include<iostream>

using namespace std;

// 0 base index
template <typename T>
class fenwick {
public:
    vector<T> fenw;
    int n;
    fenwick(int _n) : n(_n) {
        fenw.resize(n);
    }
    // index,value
    void update(int x, T v) {
        while (x < n) {
            fenw[x] += v;
            x |= (x + 1);
        }
    }
    // prefix sum till x
    T get(int x) {
        T v{};
        while (x >= 0) {
            v += fenw[x];
            x = (x & (x + 1)) - 1;
        }
        return v;
    }
    T get_range(int l, int r) {
        return get(r) - (l > 0 ? get(l - 1) : 0);
    }
};

void exploreCave(int N) {
    fenwick<int> size(N);
    for (int i = 0; i < N; i++) {
        size.update(i, 1);
    }

    int to_ask[N];
    for (int i = 0; i < N; i++)
        to_ask[i] = 0;

    vector<bool> done(N);

    auto ask = [&](int L, int R)->bool{
        for (int i = L; i <= R; i++)
            if (!done[i])
                to_ask[i] ^= 1;

        int answer = tryCombination(to_ask);
        for (int i = L; i <= R; i++)
            if (!done[i])
                to_ask[i] ^= 1;

        return answer != tryCombination(to_ask);
    };

    int S[N];
    for (int i = 0; i < N; i++) {
        int L = 0;
        while (size.get(L) != 1)
            L++;

        int R = N - 1;
        while (R - 1 >= 0 && size.get(R - 1) == N - i)
            R--;

        while (L < R) {
            int mid = (L + R) / 2;
            if (ask(L, mid)) {
                R = mid;
            } else {
                L = mid + 1;
            }
        }

        int answer = tryCombination(to_ask);
        if (answer < (i + 1))
            to_ask[R] ^= 1;

        S[i] = R;
    }

    answer(S, to_ask);
}
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 340 KB too much calls on tryCombination()
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 96 ms 424 KB too much calls on tryCombination()
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 308 KB Answer is wrong
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 308 KB Answer is wrong
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 340 KB too much calls on tryCombination()
2 Halted 0 ms 0 KB -