Submission #895371

# Submission time Handle Problem Language Result Execution time Memory
895371 2023-12-29T19:54:57 Z box Chameleon's Love (JOI20_chameleon) C++17
100 / 100
39 ms 696 KB
#include <bits/stdc++.h>
#include "chameleon.h"
using namespace std;

#define ar array
#define sz(v) int(std::size(v))
using i64 = long long;
using vi = vector<int>;

const int MAXN = 505 * 2;

vi adj[MAXN];
int who[MAXN], nex[MAXN], pre[MAXN];
vector<int> v[MAXN];
int color[MAXN];

void dfs(int i) {
    v[color[i]].push_back(i);
    for (int j : adj[i]) if (color[j] == -1) {
        color[j] = color[i] ^ 1;
        dfs(j);
    }
}

void gen(int k) {
    fill(color + 1, color + 1 + k, -1);
    exchange(v[0], {});
    exchange(v[1], {});
    for (int i = 1; i <= k; i++) if (color[i] == -1) {
        color[i] = 0;
        dfs(i);
    }
}

vi operator+(vi one, const vi two) {
    one.insert(end(one), begin(two), end(two));
    return one;
}
bool interesting(vi one) {
    if (sz(one) == 1) return false;
    return Query(one) != sz(one);
}

void Solve(int N) {
    if (N <= 50) {
        for (int i = 1; i <= N * 2; i++)
            for (int j = i + 1; j <= N * 2; j++)
                if (Query({i, j}) == 1) {
                    adj[i].push_back(j);
                    adj[j].push_back(i);
                }
    } else {
        for (int i = 1; i <= N * 2; i++) {
            gen(i - 1);
            for (int c : {0, 1})
                while (interesting(v[c] + vi{{i}})) {
                    int low = 0, hi = sz(v[c]) - 1;
                    while (low < hi) {
                        int m = (low + hi) / 2;
                        interesting(vi(begin(v[c]), begin(v[c]) + m + 1) + vi{{i}}) ? hi = m : low = m + 1;
                    }
                    adj[v[c][low]].push_back(i);
                    adj[i].push_back(v[c][low]);
                    v[c] = vi(begin(v[c]) + low + 1, end(v[c]));
                }
        }
    }
    for (int i = 1; i <= N * 2; i++) {
        assert(sz(adj[i]) == 1 || sz(adj[i]) == 3);
        if (sz(adj[i]) == 1) {
            who[i] = adj[i][0];
        } else {
            nex[i] = [&]() {
                if (Query({i, adj[i][0], adj[i][1]}) == 1) return adj[i][2];
                if (Query({i, adj[i][0], adj[i][2]}) == 1) return adj[i][1];
                return adj[i][0];
            }();
            pre[nex[i]] = i;
        }
    }
    for (int i = 1; i <= N * 2; i++) {
        if (!who[i]) {
            assert(sz(adj[i]) == 3);
            assert(pre[i] && nex[i]);
            who[i] = adj[i][0] ^ adj[i][1] ^ adj[i][2] ^ pre[i] ^ nex[i];
        }
        if (who[i] < i) Answer(who[i], i);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 392 KB Output is correct
3 Correct 16 ms 600 KB Output is correct
4 Correct 17 ms 664 KB Output is correct
5 Correct 17 ms 596 KB Output is correct
6 Correct 17 ms 600 KB Output is correct
7 Correct 19 ms 600 KB Output is correct
8 Correct 17 ms 576 KB Output is correct
9 Correct 16 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 38 ms 600 KB Output is correct
4 Correct 37 ms 600 KB Output is correct
5 Correct 37 ms 624 KB Output is correct
6 Correct 37 ms 600 KB Output is correct
7 Correct 36 ms 608 KB Output is correct
8 Correct 37 ms 632 KB Output is correct
9 Correct 37 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 392 KB Output is correct
3 Correct 16 ms 600 KB Output is correct
4 Correct 17 ms 664 KB Output is correct
5 Correct 17 ms 596 KB Output is correct
6 Correct 17 ms 600 KB Output is correct
7 Correct 19 ms 600 KB Output is correct
8 Correct 17 ms 576 KB Output is correct
9 Correct 16 ms 600 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 38 ms 600 KB Output is correct
31 Correct 37 ms 600 KB Output is correct
32 Correct 37 ms 624 KB Output is correct
33 Correct 37 ms 600 KB Output is correct
34 Correct 36 ms 608 KB Output is correct
35 Correct 37 ms 632 KB Output is correct
36 Correct 37 ms 600 KB Output is correct
37 Correct 39 ms 600 KB Output is correct
38 Correct 17 ms 544 KB Output is correct
39 Correct 39 ms 600 KB Output is correct
40 Correct 39 ms 600 KB Output is correct
41 Correct 39 ms 600 KB Output is correct
42 Correct 17 ms 600 KB Output is correct
43 Correct 37 ms 696 KB Output is correct
44 Correct 39 ms 596 KB Output is correct
45 Correct 39 ms 600 KB Output is correct