Submission #1362842

#TimeUsernameProblemLanguageResultExecution timeMemory
1362842ereringPrisoner Challenge (IOI22_prison)C++20
80 / 100
4 ms1188 KiB
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> devise_strategy(int N) {
    const int L = 8;
    vector<array<int, L>> dig(N + 1);

    for (int v = 1; v <= N; ++v) {
        int x = v - 1;
        for (int p = L - 1; p >= 0; --p) {
            dig[v][p] = x % 3;
            x /= 3;
        }
    }

    auto id = [](int p, int d) {
        return 1 + p * 3 + d;
    };

    const int final_id = 22;
    vector<vector<int>> s(23, vector<int>(N + 1, -1));

    s[0][0] = 0;
    for (int v = 1; v <= N; ++v) {
        s[0][v] = id(0, dig[v][0]);
    }

    for (int p = 0; p <= 6; ++p) {
        for (int d = 0; d < 3; ++d) {
            int cur = id(p, d);
            bool inspect_b = (p % 2 == 0);
            s[cur][0] = inspect_b ? 1 : 0;

            for (int v = 1; v <= N; ++v) {
                int od = dig[v][p];

                if (od != d) {
                    if (inspect_b) {
                        s[cur][v] = (d < od) ? -1 : -2;
                    } else {
                        s[cur][v] = (od < d) ? -1 : -2;
                    }
                    continue;
                }

                int nd = dig[v][p + 1];

                if (p < 6) {
                    s[cur][v] = id(p + 1, nd);
                } else {
                    if (nd == 1) {
                        s[cur][v] = final_id;
                    } else if (inspect_b) {
                        s[cur][v] = (nd == 0) ? -2 : -1;
                    } else {
                        s[cur][v] = (nd == 0) ? -1 : -2;
                    }
                }
            }
        }
    }

    s[final_id][0] = 0;
    for (int v = 1; v <= N; ++v) {
        int od = dig[v][7];
        if (od < 1) s[final_id][v] = -1;
        else if (od > 1) s[final_id][v] = -2;
        else s[final_id][v] = -1;
    }

    return s;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...