Submission #569887

# Submission time Handle Problem Language Result Execution time Memory
569887 2022-05-28T03:52:51 Z KoD Koala Game (APIO17_koala) C++17
100 / 100
72 ms 332 KB
#include "koala.h"
#include <bits/stdc++.h>

int minValue(int N, int W) {
    int B[100] = {}, R[100] = {};
    B[0] = 1;
    playRound(B, R);
    for (int i = 1; i < N; ++i) {
        if (R[i] == 0) {
            return i;
        }
    }
    return 0;
}

int maxValue(int N, int W) {
    int B[100] = {}, R[100] = {};
    std::vector<int> cand(N);
    std::iota(cand.begin(), cand.end(), 0);
    while (cand.size() > 1) {
        const int x = W / (int)cand.size();
        for (const int i : cand) {
            B[i] = x;
        }
        playRound(B, R);
        std::vector<int> next;
        for (const int i : cand) {
            if (B[i] < R[i]) {
                next.push_back(i);
            }
            B[i] = 0;
        }
        cand = std::move(next);
    }
    return cand[0];
}

int greaterValue(int N, int W) {
    int B[100] = {}, R[100] = {};
    const auto put_and_play = [&](const int x) {
        B[0] = B[1] = x;
        playRound(B, R);
        return (B[0] < R[0]) + (B[1] < R[1]);
    };
    const int a = put_and_play(4);
    if (a == 2) {
        put_and_play(8);
    } else if (a == 0) {
        const int b = put_and_play(2);
        if (b == 0) {
            put_and_play(1);
        }
    }
    return B[1] < R[1];
}

template <class F>
struct fixed_point : private F {
    explicit fixed_point(F&& f) : F(std::forward<F>(f)) {}
    template <class... Args>
    decltype(auto) operator()(Args&&... args) const {
        return F::operator()(*this, std::forward<Args>(args)...);
    }
};

void allValues(int N, int W, int* P) {
    int B[100] = {}, R[100] = {};
    if (W == 2 * N) {
        std::vector<int> ord(N);
        std::iota(ord.begin(), ord.end(), 0);
        fixed_point([&](auto&& dfs, const int l, const int r) -> void {
            if (r - l == 1) {
                return;
            }
            const int m = (l + r) / 2;
            dfs(l, m);
            dfs(m, r);
            std::inplace_merge(ord.begin() + l, ord.begin() + m, ord.begin() + r,
                               [&](const int i, const int j) {
                                   B[i] = B[j] = N;
                                   playRound(B, R);
                                   const bool ret = B[j] < R[j];
                                   B[i] = B[j] = 0;
                                   return ret;
                               });
        })(0, N);
        for (int i = 0; i < N; ++i) {
            P[ord[i]] = i + 1;
        }
    } else {
        std::vector<int> v(N);
        std::iota(v.begin(), v.end(), 0);
        fixed_point([&](auto&& dfs, const int l, std::vector<int> v) -> void {
            if (v.size() == 1) {
                P[v[0]] = l;
            } else {
                std::fill(B, B + N, 0);
                const int w = std::min<int>(W / v.size(), std::sqrt(2 * l));
                for (const int i : v) {
                    B[i] = w;
                }
                playRound(B, R);
                std::vector<int> a, b;
                for (const int i : v) {
                    (R[i] <= w ? a : b).push_back(i);
                }
                const int r = l + a.size();
                dfs(l, std::move(a));
                dfs(r, std::move(b));
            }
        })(1, std::move(v));
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 208 KB Output is correct
2 Correct 4 ms 208 KB Output is correct
3 Correct 4 ms 208 KB Output is correct
4 Correct 4 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 320 KB Output is correct
2 Correct 14 ms 320 KB Output is correct
3 Correct 13 ms 316 KB Output is correct
4 Correct 12 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 320 KB Output is correct
2 Correct 61 ms 324 KB Output is correct
3 Correct 72 ms 324 KB Output is correct
4 Correct 58 ms 328 KB Output is correct
5 Correct 64 ms 328 KB Output is correct
6 Correct 58 ms 316 KB Output is correct
7 Correct 58 ms 320 KB Output is correct
8 Correct 56 ms 320 KB Output is correct
9 Correct 57 ms 332 KB Output is correct
10 Correct 60 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 208 KB Output is correct
2 Correct 36 ms 252 KB Output is correct
3 Correct 37 ms 292 KB Output is correct
4 Correct 31 ms 208 KB Output is correct
5 Correct 30 ms 316 KB Output is correct
6 Correct 27 ms 296 KB Output is correct
7 Correct 27 ms 208 KB Output is correct
8 Correct 29 ms 208 KB Output is correct
9 Correct 28 ms 316 KB Output is correct
10 Correct 27 ms 316 KB Output is correct
11 Correct 29 ms 316 KB Output is correct
12 Correct 19 ms 208 KB Output is correct
13 Correct 28 ms 208 KB Output is correct
14 Correct 29 ms 316 KB Output is correct
15 Correct 33 ms 208 KB Output is correct
16 Correct 32 ms 208 KB Output is correct
17 Correct 25 ms 312 KB Output is correct
18 Correct 25 ms 208 KB Output is correct
19 Correct 25 ms 208 KB Output is correct
20 Correct 27 ms 292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 208 KB Output is correct
2 Correct 3 ms 208 KB Output is correct
3 Correct 3 ms 208 KB Output is correct
4 Correct 3 ms 208 KB Output is correct
5 Correct 3 ms 208 KB Output is correct
6 Correct 3 ms 320 KB Output is correct
7 Correct 4 ms 208 KB Output is correct
8 Correct 4 ms 208 KB Output is correct
9 Correct 3 ms 208 KB Output is correct
10 Correct 3 ms 208 KB Output is correct
11 Correct 3 ms 208 KB Output is correct
12 Correct 3 ms 208 KB Output is correct
13 Correct 4 ms 208 KB Output is correct
14 Correct 3 ms 208 KB Output is correct
15 Correct 3 ms 208 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 4 ms 208 KB Output is correct
18 Correct 3 ms 208 KB Output is correct
19 Correct 3 ms 324 KB Output is correct
20 Correct 3 ms 208 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 4 ms 208 KB Output is correct
23 Correct 3 ms 208 KB Output is correct
24 Correct 3 ms 208 KB Output is correct
25 Correct 3 ms 208 KB Output is correct
26 Correct 3 ms 208 KB Output is correct
27 Correct 3 ms 316 KB Output is correct
28 Correct 3 ms 208 KB Output is correct
29 Correct 4 ms 208 KB Output is correct
30 Correct 4 ms 208 KB Output is correct
31 Correct 3 ms 208 KB Output is correct
32 Correct 3 ms 208 KB Output is correct
33 Correct 4 ms 208 KB Output is correct
34 Correct 5 ms 316 KB Output is correct
35 Correct 3 ms 208 KB Output is correct
36 Correct 5 ms 208 KB Output is correct
37 Correct 3 ms 208 KB Output is correct
38 Correct 4 ms 208 KB Output is correct
39 Correct 3 ms 208 KB Output is correct
40 Correct 4 ms 208 KB Output is correct