제출 #839956

#제출 시각아이디문제언어결과실행 시간메모리
839956SorahISACoreputer (IOI23_coreputer)C++17
100 / 100
1 ms464 KiB
#ifndef SorahISA
#define SorahISA
#include SorahISA __FILE__ SorahISA

int N;
vector<int> mem;

int query(int mask) {
    mask &= ((1 << N) - 1);
    // cerr << "query: " << bitset<16>(mask).to_string() << "\n";
    if (mem[mask] != -2) return mem[mask];
    // cerr << "                        +\n";
    vector<int> ask;
    for (int i = 0; i < N; ++i) {
        if (mask >> i & 1) ask.eb(i);
    }
    return mem[mask] = run_diagnostic(ask);
}

vector<int> malfunctioning_cores(int _N) {
    N = _N, mem.assign(1<<N, -2);
    mem[0] = -1, mem.back() = 1;
    
    int thres = 0;
    for (int delta = (1 << __lg(N)); delta; delta >>= 1) {
        int mask = 0;
        for (int bit = 0; bit < thres+delta; ++bit) mask |= (1 << bit);
        if (query(mask) == -1) thres += delta;
    }
    
    int parity = query((1 << (thres+1)) - 1);
    
    vector<int> ans(N, -1);
    ans[thres] = 1;
    int left = N-1;
    
    int L = 0, R = thres, mask = (1 << (R+1)) - (1 << L);
    while (left > 1) {
        if (query(mask) != -1) {
            mask &= ~(1 << L);
            if (ans[L] != -1) mem[mask] = (ans[L] ? -1 : 1);
            else ans[L] = (query(mask) == -1), --left;
            L = (L + 1) % N;
        }
        else {
            R = (R + 1) % N;
            mask |= (1 << R);
            if (ans[R] != -1) mem[mask] = (ans[R] ? 1 : -1);
            else ans[R] = (query(mask) != -1), --left;
        }
    }
    
    int left_id = -1;
    for (int i = 0; i < N; ++i) {
        if (ans[i] == -1) left_id = i;
        else parity ^= ans[i];
    }
    ans[left_id] = parity;
    
    return ans;
}

#else

#include "coreputer.h"
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;

// #define int int64_t
// #define double __float80
using pii = pair<int, int>;
template <typename T> using Prior = std::priority_queue<T>;
template <typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>;

// #define X first
// #define Y second
#define eb emplace_back
#define ef emplace_front
#define ee emplace
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define SZ(x) ((int)(x).size())

#ifdef local
#define fastIO() void()
#define debug(...) \
    fprintf(stderr, "%sAt [%s], line %d: (%s) = ", "\u001b[33m", __FUNCTION__, __LINE__, #__VA_ARGS__), \
    _do(__VA_ARGS__), fprintf(stderr, "%s", "\u001b[0m")
template <typename T> void _do(T &&_t) {cerr << _t << "\n";}
template <typename T, typename ...U> void _do(T &&_t, U &&..._u) {cerr << _t << ", ", _do(_u...);}
#else
#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define debug(...) void()
#endif

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

template <typename T, typename U> bool chmin(T &lhs, U rhs) {return lhs > rhs ? lhs = rhs, 1 : 0;}
template <typename T, typename U> bool chmax(T &lhs, U rhs) {return lhs < rhs ? lhs = rhs, 1 : 0;}

#endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...