답안 #1022660

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1022660 2024-07-13T21:34:51 Z PurpleCrayon 카멜레온의 사랑 (JOI20_chameleon) C++17
44 / 100
28 ms 600 KB
#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;

#define sz(v) int(v.size())
#define ar array
typedef long long ll;
const int N = 5e2+10, MOD = 1e9+7;

namespace {

}  // namespace

vector<int> adj[2 * N];
vector<int> vis; 

void dfs_col(int c, int b) {
    vis[c] = b;
    for (int nxt : adj[c]) if (vis[nxt] == -1)
        dfs_col(nxt, b ^ 1);
}

vector<int> build_cols(vector<pair<int, int>> edges, int l, int r) {
    vis.assign(r + 1, -1);
    for (int i = l; i <= r; i++)
        adj[i].clear();

    for (auto [a, b] : edges)
        adj[a].push_back(b), adj[b].push_back(a);

    for (int i = l; i <= r; i++) if (vis[i] == -1)
        dfs_col(i, 0);

    return vis;
}

vector<pair<int, int>> rec(int l, int r) {
    if (l >= r) return {};
    int m = (l + r) / 2;
    auto edges_one = rec(l, m), edges_two = rec(m + 1, r);
    vector<pair<int, int>> edges;
    for (auto e : edges_one) edges.push_back(e);
    for (auto e : edges_two) edges.push_back(e);

    auto cols = build_cols(edges_two, m + 1, r);
    vector<int> one, two;
    for (int i = m + 1; i <= r; i++) {
        if (cols[i])
            one.push_back(i);
        else
            two.push_back(i);
    }

    for (int i = l; i <= m; i++) {
        for (int rep = 0; rep < 2; rep++) {
            auto check = [&](int L, int R) {
                vector<int> v{i};
                for (int j = L; j <= R; j++)
                    v.push_back(one[j]);

                if (Query(v) != sz(v))
                    return true;
                else
                    return false;
            };

            int L = 0;
            while (L < sz(one)) {
                if (!check(L, sz(one)-1))
                    break;

                int lo = -1, hi = sz(one)-1, mid = (lo + hi) / 2;
                while (lo < mid && mid < hi) {
                    if (check(L, mid)) hi = mid;
                    else lo = mid;
                    mid = (lo + hi) / 2;
                }

                edges.emplace_back(i, one[hi]);
                L = hi + 1;
            }

            swap(one, two);
        }
    }

    return edges;
}

void Solve(int n) {
    auto edges = rec(1, 2*n);
    vector<vector<int>> adj(2 * n + 1);
    vector<int> out(2 * n + 1);
    for (auto [a, b] : edges) {
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    for (int i = 1; i <= 2 * n; i++) {
        if (sz(adj[i]) == 1) {
            continue;
        }

        assert(sz(adj[i]) == 3);
        random_shuffle(adj[i].begin(), adj[i].end());
        out[i] = adj[i][2];
        for (int j = 0; j <= 1; j++) {
            vector<int> v{i};
            for (int k = 0; k < 3; k++) if (k != j)
                v.push_back(adj[i][k]);

            if (Query(v) == 1) {
                out[i] = adj[i][j];
                break;
            }
        }
    }

    for (int a = 1; a <= 2 * n; a++) {
        for (int b : adj[a]) {
            if (out[a] == b) continue;
            if (out[b] == a) continue;
            if (a > b) continue;
            Answer(a, b);
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 16 ms 548 KB Output is correct
4 Correct 15 ms 600 KB Output is correct
5 Correct 19 ms 560 KB Output is correct
6 Correct 15 ms 600 KB Output is correct
7 Correct 15 ms 536 KB Output is correct
8 Correct 16 ms 600 KB Output is correct
9 Correct 16 ms 600 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 372 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 28 ms 560 KB Wrong Answer [3]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 16 ms 548 KB Output is correct
4 Correct 15 ms 600 KB Output is correct
5 Correct 19 ms 560 KB Output is correct
6 Correct 15 ms 600 KB Output is correct
7 Correct 15 ms 536 KB Output is correct
8 Correct 16 ms 600 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 0 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 372 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 Incorrect 28 ms 560 KB Wrong Answer [3]
31 Halted 0 ms 0 KB -