Submission #839956

# Submission time Handle Problem Language Result Execution time Memory
839956 2023-08-30T22:08:13 Z SorahISA Coreputer (IOI23_coreputer) C++17
100 / 100
1 ms 464 KB
#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 time Memory Grader output
1 Correct 0 ms 296 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 0 ms 208 KB Output is correct
16 Correct 0 ms 208 KB Output is correct
17 Correct 0 ms 208 KB Output is correct
18 Correct 0 ms 208 KB Output is correct
19 Correct 0 ms 208 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 0 ms 336 KB Output is correct
22 Correct 0 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 0 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 0 ms 336 KB Output is correct
27 Correct 0 ms 464 KB Output is correct
28 Correct 0 ms 464 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 1 ms 464 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
36 Correct 1 ms 464 KB Output is correct
37 Correct 0 ms 464 KB Output is correct
38 Correct 0 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 296 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 0 ms 208 KB Output is correct
16 Correct 0 ms 208 KB Output is correct
17 Correct 0 ms 208 KB Output is correct
18 Correct 0 ms 208 KB Output is correct
19 Correct 0 ms 208 KB Output is correct
20 Correct 0 ms 208 KB Output is correct
21 Correct 0 ms 208 KB Output is correct
22 Correct 0 ms 208 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 0 ms 336 KB Output is correct
25 Correct 0 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 0 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 0 ms 336 KB Output is correct
30 Correct 0 ms 464 KB Output is correct
31 Correct 0 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
36 Correct 1 ms 464 KB Output is correct
37 Correct 1 ms 464 KB Output is correct
38 Correct 1 ms 464 KB Output is correct
39 Correct 1 ms 464 KB Output is correct
40 Correct 0 ms 464 KB Output is correct
41 Correct 0 ms 464 KB Output is correct
42 Correct 0 ms 208 KB Output is correct
43 Correct 0 ms 208 KB Output is correct
44 Correct 0 ms 208 KB Output is correct
45 Correct 0 ms 208 KB Output is correct
46 Correct 0 ms 208 KB Output is correct
47 Correct 0 ms 208 KB Output is correct
48 Correct 0 ms 208 KB Output is correct
49 Correct 0 ms 208 KB Output is correct
50 Correct 0 ms 208 KB Output is correct
51 Correct 0 ms 208 KB Output is correct
52 Correct 0 ms 208 KB Output is correct
53 Correct 0 ms 208 KB Output is correct
54 Correct 0 ms 208 KB Output is correct
55 Correct 0 ms 208 KB Output is correct
56 Correct 0 ms 208 KB Output is correct
57 Correct 0 ms 208 KB Output is correct
58 Correct 0 ms 208 KB Output is correct
59 Correct 0 ms 208 KB Output is correct
60 Correct 0 ms 208 KB Output is correct
61 Correct 0 ms 208 KB Output is correct
62 Correct 0 ms 208 KB Output is correct
63 Correct 0 ms 208 KB Output is correct
64 Correct 0 ms 208 KB Output is correct
65 Correct 0 ms 208 KB Output is correct
66 Correct 0 ms 208 KB Output is correct
67 Correct 0 ms 404 KB Output is correct
68 Correct 0 ms 336 KB Output is correct
69 Correct 1 ms 336 KB Output is correct
70 Correct 0 ms 336 KB Output is correct
71 Correct 1 ms 464 KB Output is correct
72 Correct 0 ms 464 KB Output is correct
73 Correct 0 ms 464 KB Output is correct
74 Correct 1 ms 464 KB Output is correct
75 Correct 1 ms 464 KB Output is correct
76 Correct 1 ms 464 KB Output is correct
77 Correct 1 ms 464 KB Output is correct
78 Correct 0 ms 464 KB Output is correct
79 Correct 1 ms 464 KB Output is correct
80 Correct 1 ms 464 KB Output is correct
81 Correct 1 ms 464 KB Output is correct
82 Correct 1 ms 464 KB Output is correct