This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int BASE = 3;
int SHIFT = (BASE - 1);
int get_bit(int num, int digit) {
    for (int i = 0; i < digit; i ++) {
        num /= BASE;
    }
    return num % BASE;
}
vector<vector<int>> devise_strategy(int N) {
    int digits = log(N) / log(BASE) + 1;
    // VVV questo ma con base diversa da 2 per minimizzare X
    // 3 * xxxxxx + y
    // x = quale cifra sto guardando, sapendo che quelle più alte sono uguali
    // y =  0 : sono in B e il bit di A è 0
    //      1 : sono in B e il bit di A è 1
    //      2 : sono in A e devo passare il bit di A in B
    vector<vector<int>> s((BASE) * (digits + 1) - SHIFT, vector<int>(N + 1));
    // shifta tutto di B perché con digit == 0 c'è un solo caso (l'inizio), così risparmi numeri.
    for (int x = 0; x < (BASE) * (digits + 1) - SHIFT; x ++) {
        int real_x = x + SHIFT;
        int bit = real_x % BASE;
        int digit = real_x / BASE;
        // cout << "--- x, real_x : " << x <<  " " << real_x << '\n';
        // cout << "bit, digit : " << bit << " " << digit << '\n';
        // cout << "who, bit, digit " << who << " " << bit << " " << digit << '\n';
        if (x == 0) {
            // start, occupa un po' di casi ma è solo uno tho
            int digit_next = digits;
            s[x][0] = (digits + 1) % 2;
            // cout << "seleziono " << (digits + 1) % 2 << '\n';
            for (int j = 1; j <= N; j ++) {
                int bit_next = get_bit(j, digit_next - 1);
                s[x][j] = (digit_next * BASE) + bit_next - SHIFT;
                // cout << "j : " << s[x][j] << '\n';
            }
            continue;
        }
        // cout << "CASO DIGIT" << '\n';
        s[x][0] = (digit % 2);
        // cout << "seleziono " << (digit % 2) << '\n';
        int digit_next = digit;
        // cout << "digit_next -> " << digit_next << '\n'; 
        for (int j = 1; j <= N; j ++) {
            int bit_next = get_bit(j, digit_next - 1);
            // cout << "bit_next : " << bit_next << '\n';
            if (bit_next < bit) s[x][j] = (digit % 2) ? -2 : -1;
            if (bit < bit_next) s[x][j] = (digit % 2) ? -1 : -2;
        }
        digit_next -= 1;
        // cout << "digit_next : " << digit_next << '\n';
        for (int j = 1; j <= N; j ++) {
            int bit_next = get_bit(j, digit_next - 1);
            // cout << "bit_next : " << bit_next << '\n';
            if (s[x][j] != -1 && s[x][j] != -2 && digit_next > 1) { // in teoria non ci arriva, ma non potrebbe
                // cout << "orig : " << (digit_next * (BASE + 1)) + BASE << '\n';
                s[x][j] = (digit_next * BASE) + bit_next - SHIFT;
                // cout << digit_next << " * " << BASE << " + " << bit_next << " - " << SHIFT << '\n';
            }
            // cout << "j : " << s[x][j] << '\n';
            // cout << s[x][j] << '\n';
        }
    }
    
    return s;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |