답안 #979681

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
979681 2024-05-11T09:53:03 Z Pannda 카멜레온의 사랑 (JOI20_chameleon) C++14
100 / 100
28 ms 596 KB
#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;

void Solve(int n) {
    auto query = [&](vector<int> p) -> int {
        for (int &i : p) i++;
        return Query(p);
    };
    auto answer = [&](int i, int j) -> void {
        Answer(i + 1, j + 1);
    };
    auto sum = [&](vector<int> a, vector<int> b) -> vector<int> {
        a.insert(a.end(), b.begin(), b.end());
        return a;
    };

    vector<vector<int>> adj(2 * n);

    auto work = [&](auto self, vector<int> p) -> void {
        vector<int> p0, p1;
        for (int u : p) {
            if (query(sum(p0, {u})) == p0.size() + 1) {
                p0.push_back(u);
            } else {
                p1.push_back(u);
            }
        }
        swap(p0, p1);
        for (int u : p0) {
            vector<int> p = p1;
            while (true) {
                int l = 0, r = p.size();
                while (l + 1 < r) {
                    int m = (l + r) >> 1;
                    if (query(sum(vector<int>(p.begin() + l, p.begin() + m), {u})) < m - l + 1) {
                        r = m;
                    } else {
                        l = m;
                    }
                }
                int v = p[l];
                adj[u].push_back(v);
                adj[v].push_back(u);
                p.erase(p.begin() + l);
                if (query(sum(p, {u})) == p.size() + 1) break;
            }
        }
        if (!p0.empty()) self(self, p0);
    };
    work(work, [&]() -> vector<int> { vector<int> p(2 * n); iota(p.begin(), p.end(), 0); return p; }());

    for (int u = 0; u < 2 * n; u++) {
        for (int i = 0; i < 3 && adj[u].size() == 3; i++) {
            for (int j = i + 1; j < 3 && adj[u].size() == 3; j++) {
                if (query({u, adj[u][i], adj[u][j]}) == 1) {
                    adj[u] = {adj[u][i], adj[u][j]};
                }
            }
        }
    }

    for (int u = 0; u < 2 * n; u++) {
        for (int v : adj[u]) {
            if (find(adj[v].begin(), adj[v].end(), u) != adj[v].end()) {
                if (u < v) answer(u, v);
            }
        }
    }
}

Compilation message

chameleon.cpp: In instantiation of 'Solve(int)::<lambda(auto:1, std::vector<int>)> [with auto:1 = Solve(int)::<lambda(auto:1, std::vector<int>)>]':
chameleon.cpp:51:103:   required from here
chameleon.cpp:23:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |             if (query(sum(p0, {u})) == p0.size() + 1) {
      |                 ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
chameleon.cpp:46:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |                 if (query(sum(p, {u})) == p.size() + 1) break;
      |                     ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 10 ms 344 KB Output is correct
4 Correct 10 ms 344 KB Output is correct
5 Correct 10 ms 344 KB Output is correct
6 Correct 11 ms 344 KB Output is correct
7 Correct 10 ms 344 KB Output is correct
8 Correct 10 ms 344 KB Output is correct
9 Correct 10 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 1 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 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 596 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 1 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 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 596 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 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 448 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 Correct 23 ms 340 KB Output is correct
4 Correct 23 ms 344 KB Output is correct
5 Correct 23 ms 556 KB Output is correct
6 Correct 23 ms 344 KB Output is correct
7 Correct 24 ms 344 KB Output is correct
8 Correct 28 ms 344 KB Output is correct
9 Correct 23 ms 536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 10 ms 344 KB Output is correct
4 Correct 10 ms 344 KB Output is correct
5 Correct 10 ms 344 KB Output is correct
6 Correct 11 ms 344 KB Output is correct
7 Correct 10 ms 344 KB Output is correct
8 Correct 10 ms 344 KB Output is correct
9 Correct 10 ms 344 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 1 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 1 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 596 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 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 448 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 23 ms 340 KB Output is correct
31 Correct 23 ms 344 KB Output is correct
32 Correct 23 ms 556 KB Output is correct
33 Correct 23 ms 344 KB Output is correct
34 Correct 24 ms 344 KB Output is correct
35 Correct 28 ms 344 KB Output is correct
36 Correct 23 ms 536 KB Output is correct
37 Correct 22 ms 344 KB Output is correct
38 Correct 10 ms 552 KB Output is correct
39 Correct 21 ms 344 KB Output is correct
40 Correct 22 ms 344 KB Output is correct
41 Correct 22 ms 548 KB Output is correct
42 Correct 10 ms 344 KB Output is correct
43 Correct 23 ms 344 KB Output is correct
44 Correct 22 ms 344 KB Output is correct
45 Correct 22 ms 344 KB Output is correct