Submission #1272319

#TimeUsernameProblemLanguageResultExecution timeMemory
1272319hubertmPrisoner Challenge (IOI22_prison)C++20
0 / 100
2 ms960 KiB
#include "prison.h"

#include <bits/stdc++.h>

using namespace std;

constexpr int base = 3;
constexpr int maxBit = 1;
constexpr int x = (maxBit + 1) * base;

int getStep(int n)
{
    return (n + base - 1) / base;
}

int getBit(int n, int b)
{
    for (int i = 0; i < b; ++i) n /= base;

    return n % base;
}

vector<vector<int>> devise_strategy(int N)
{
    vector<vector<int>> strategy;
    for (int n = 0; n <= x - 2; ++n)
    {
        vector<int> current(N + 1);
        int step = getStep(n);

        current[0] = (step & 1);

        for (int j = 1; j <= N; ++j)
        {
            int v = getBit(j, maxBit - step + 1);

            int written = (n - 1) % base;

            if (step == maxBit + 1) written = 1;

            if (step != 0 && v > written)
            {
                if (step & 1)
                    current[j] = -1;
                else
                    current[j] = -2;
                continue;
            }
            else if (step != 0 && written > v)
            {
                if (step & 1)
                    current[j] = -2;
                else
                    current[j] = -1;
                continue;
            }

            if (step == maxBit + 1) continue;

            v = getBit(j, maxBit - step);

            if (step == maxBit)
            {
                if (v == 2)
                {
                    if (step & 1)
                        current[j] = -1;
                    else
                        current[j] = -2;
                }
                else if (v == 0)
                {
                    if (step & 1)
                        current[j] = -2;
                    else
                        current[j] = -1;
                }
                else
                {
                    current[j] = step * base + 1;
                }
                continue;
            }

            current[j] = step * base + v + 1;
        }

        strategy.push_back(current);
    }

    // for (int i = 0; i <= x - 2; ++i)
    // {
    //     for (int v : strategy[i]) cout << v << ' ';
    //     cout << '\n';
    // }

    return strategy;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...