답안 #1010424

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1010424 2024-06-29T05:52:08 Z sleepntsheep 마술쇼 (APIO24_show) C++17
0 / 100
8 ms 1320 KB
#include <vector>
#include "Alice.h"
#include <cstdlib>

namespace {
    using u64 = unsigned long long;
    u64 coeff[5001];
    void init() {
        srand(8686);
        for (int i = 0; i < 5001; ++i) {
            coeff[i] = rand();
            coeff[i] *= rand();
            coeff[i] *= rand();
        }
    }
};


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 (u64 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 <cstdlib>
#include <algorithm>
#include "Bob.h"
#include <cstring>


namespace {
    using u64 = unsigned long long;
    u64 coeff[5001];
    void init() {
        srand(8686);
        for (int i = 0; i < 5001; ++i) {
            coeff[i] = rand();
            coeff[i] *= rand();
            coeff[i] *= rand();
        }
    }
};


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;
        for (int i = 3; piv == -1; ++i)
            if (ans[i] != -1 && !used[i] && ((coeff[i] >> j) & 1)) {
                used[i] = 1;
                piv = i;
            }

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

            ans[i] ^= ans[piv];
            for (long long k = 59; k >= 0; --k)
                coeff[i] ^= (((coeff[piv] >> k) & 1) << k);
        }
        pivot[j] = piv;
    }

    x = 0;
    for (long long j = 0; j < 60; ++j) {
        for (long long k = 0; k < 60; ++k) {
            if (k != j)
                assert(0 == ((coeff[pivot[j]] >> k) & 1));
        }
        if (ans[pivot[j]])
            x ^= 1ll << j;
    }
    return x;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1068 KB Correct.
2 Correct 6 ms 1064 KB Correct.
3 Correct 7 ms 1220 KB Correct.
4 Runtime error 7 ms 1320 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1068 KB Correct.
2 Correct 6 ms 1064 KB Correct.
3 Correct 7 ms 1220 KB Correct.
4 Runtime error 7 ms 1320 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1068 KB Correct.
2 Correct 6 ms 1064 KB Correct.
3 Correct 7 ms 1220 KB Correct.
4 Runtime error 7 ms 1320 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -