Submission #1010452

# Submission time Handle Problem Language Result Execution time Memory
1010452 2024-06-29T06:19:54 Z sleepntsheep Magic Show (APIO24_show) C++17
0 / 100
9 ms 1328 KB
#include <vector>
#include <random>
#include "Alice.h"

namespace {
    long long coeff[5001];
    void init() {
        std::mt19937 gen(868686);
        std::uniform_int_distribution<long long> dis(0, (1ll << 60) - 1);
        for (int i = 0; i < 5001; ++i)
            coeff[i] = dis(gen);
    }
};


std::vector<std::pair<int,int>> Alice(){
    init();

    long long x = setN(5000);
    int i, ans;

    std::vector<std::pair<int, int > > T = { {1, 2} };

    for (i = 3; i <= 5000; ++i) {
        ans = 0;
        for (long long j = 0; j < 60; ++j)
            ans ^= ((coeff[i] >> j) & 1) * ((x >> j) & 1);
        T.emplace_back(i, 1 + ans);
    }

    return T;
}
#include <vector>
#include <cassert>
#include <algorithm>
#include "Bob.h"
#include <cstring>
#include <random>


namespace {
    long long coeff[5001];
    std::mt19937 gen(868686);
    void init() {
        std::uniform_int_distribution<long long> dis(0, (1ll << 60) - 1);
        for (int i = 0; i < 5001; ++i)
            coeff[i] = dis(gen);
    }
};


long long Bob(std::vector<std::pair<int,int>> T) {
    long long x;
    int pivot[60] = { 0 };
    int ans[5001] = { 0 };
    int used[5001] = { 0 };
    memset(ans, -1, sizeof ans);
    memset(used, 0, sizeof used);

    for (auto [u, v] : T) {
        if (u > v)
            std::swap(u, v);
        if (v <= 2)
            continue;
        ans[v] = u - 1;
    }

    init();

    for (int j = 59; j >= 0; --j) {
        int piv = -1;
        std::vector<int> ok;
        for (int i = 3; i <= 5000; ++i)
            if (ans[i] != -1 && !used[i] && ((coeff[i] >> j) & 1))
                ok.push_back(i);
        if (ok.empty())return Bob(T);
        std::uniform_int_distribution<long long> dis(0, ok.size() - 1);
        piv = ok[dis(gen)];
        used[piv] = 1;

        for (int i = 3; i <= 5000; ++i) {
            if (ans[i] == -1 || i == piv || 0 == ((coeff[i] >> j) & 1))
                continue;

            ans[i] ^= ans[piv];
            coeff[i] ^= coeff[piv];
        }

        pivot[j] = piv;
    }

    x = 0;
    for (long long j = 0; j < 60; ++j)
        x ^= ans[pivot[j]] << j;
    return x;
}

# Verdict Execution time Memory Grader output
1 Correct 6 ms 1328 KB Correct.
2 Correct 5 ms 1064 KB Correct.
3 Incorrect 9 ms 1328 KB Incorrect answer.
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1328 KB Correct.
2 Correct 5 ms 1064 KB Correct.
3 Incorrect 9 ms 1328 KB Incorrect answer.
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1328 KB Correct.
2 Correct 5 ms 1064 KB Correct.
3 Incorrect 9 ms 1328 KB Incorrect answer.
4 Halted 0 ms 0 KB -