제출 #21590

#제출 시각아이디문제언어결과실행 시간메모리
21590UshioBroken Device (JOI17_broken_device)C++14
100 / 100
52 ms4636 KiB
#include "Annalib.h"
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;

void Anna(int N, long long X, int K, int P[] ){
    vector<int> bits(N);
    for (int i = 0; i < N; ++i) {
        bits[i] = i >= 60 ? 0: ((X & (1LL << i)) != 0);
    }
    vector<int> bad(N, 0);
    for (int i = 0; i < K; ++i) {
        bad[P[i]] = 1;
    }
    int pos = 0;
    for (int i = 0; i < N; i += 3) {
        int cnt = bad[i] + bad[i + 1] + bad[i + 2];
        if (cnt == 0) {
            if (bits[pos] == 0 && bits[pos + 1] == 0) {
                Set(i    , 1);
                Set(i + 1, 0);
                Set(i + 2, 0);
            } else if (bits[pos] == 0 && bits[pos + 1] == 1) {
                Set(i    , 1);
                Set(i + 1, 0);
                Set(i + 2, 1);
            } else if (bits[pos + 1] == 0) {
                Set(i    , 0);
                Set(i + 1, 1);
                Set(i + 2, 1);
            } else {
                Set(i    , 1);
                Set(i + 1, 1);
                Set(i + 2, 1);
            }
            pos += 2;
        } else if (cnt == 1) {
            if (bits[pos] == 0) {
                if (!bad[i + 1]) {
                    Set(i    , 0);
                    Set(i + 1, 1);
                    Set(i + 2, 0);
                    pos += 1;
                } else if (bits[pos + 1] == 0) {
                    Set(i    , 1);
                    Set(i + 1, 0);
                    Set(i + 2, 0);
                    pos += 2;
                } else {
                    Set(i    , 1);
                    Set(i + 1, 0);
                    Set(i + 2, 1);
                    pos += 2;
                }
            } else if (bad[i + 2]) {
                Set(i    , 1);
                Set(i + 1, 1);
                Set(i + 2, 0);
                pos += 1;
            } else {
                Set(i    , 0);
                Set(i + 1, 0);
                Set(i + 2, 1);
                pos += 1;
            }
        } else {
            Set(i, 0);
            Set(i + 1, 0);
            Set(i + 2, 0);
        }
    }
}
#include "Brunolib.h"
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;

const int64_t value[] = {0, 1, 0, 1, 0, 2, 1, 3};
const int add[] = {0, 1, 1, 2, 2, 2, 1, 2};

long long Bruno( int N, int A[] ){
    vector<int> bits(N, 0);
    int64_t ans = 0;
    int shift = 0;
    for (int i = 0; i < N; i += 3) {
        int v = 4 * A[i] + 2 * A[i + 1] + A[i + 2];
        ans |= value[v] << shift;
        shift += add[v];
    }
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...