제출 #1350394

#제출 시각아이디문제언어결과실행 시간메모리
1350394MisterReaperBroken Device (JOI17_broken_device)C++20
100 / 100
20 ms1592 KiB
#include "Annalib.h"
#include <bits/stdc++.h>

namespace {    

using i64 = long long;

#ifdef DEBUG 
    #include "/home/ahmetalp/Desktop/Workplace/debug.h"
#else
    #define debug(...) void(23)
#endif

std::mt19937 rng(232323);

};

void Anna(int N, i64 X, int K, int P[]) {
    std::vector<int> bad(N);
    for (int i = 0; i < K; ++i) {
        bad[P[i]] = true;
    }

    std::vector<int> p(N);
    std::iota(p.begin(), p.end(), 0);
    std::shuffle(p.begin(), p.end(), rng);

    for (int i = 0; i < N; i += 2) {
        if (bad[p[i]] && bad[p[i + 1]]) {
            Set(p[i], 0);
            Set(p[i + 1], 0);
        } else if (bad[p[i]]) {
            if (X % 3 == 0) {
                Set(p[i], 0);
                Set(p[i + 1], 1);
                X /= 3;
            } else {
                Set(p[i], 0);
                Set(p[i + 1], 0);
            }
        } else if (bad[p[i + 1]]) {
            if (X % 3 == 1) {
                Set(p[i], 1);
                Set(p[i + 1], 0);
                X /= 3;
            } else {
                Set(p[i], 0);
                Set(p[i + 1], 0);
            }
        } else {
            if (X % 3 == 0) {
                Set(p[i], 0);
                Set(p[i + 1], 1);
            } else if (X % 3 == 1) {
                Set(p[i], 1);
                Set(p[i + 1], 0);
            } else {
                Set(p[i], 1);
                Set(p[i + 1], 1);
            }
            X /= 3;
        }
    }
}
#include "Brunolib.h"
#include <bits/stdc++.h>

namespace {

using i64 = long long;

#ifdef DEBUG 
    #include "/home/ahmetalp/Desktop/Workplace/debug.h"
#else
    #define debug(...) void(23)
#endif

std::mt19937 rng(232323);

};

i64 Bruno(int N, int A[]) {
    std::vector<int> p(N);
    std::iota(p.begin(), p.end(), 0);
    std::shuffle(p.begin(), p.end(), rng);

    i64 X = 0;

    for (int i = N - 2; i >= 0; i -= 2) {
        if (A[p[i]] == 0 && A[p[i + 1]] == 0) {
            continue;
        } else if (A[p[i]] == 0 && A[p[i + 1]] == 1) {
            X = X * 3;
        } else if (A[p[i]] == 1 && A[p[i + 1]] == 0) {
            X = X * 3 + 1;
        } else {
            X = X * 3 + 2;
        }
    }

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