답안 #937783

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
937783 2024-03-04T13:03:04 Z Pring 카멜레온의 사랑 (JOI20_chameleon) C++17
100 / 100
39 ms 604 KB
#include <bits/stdc++.h>
#include "chameleon.h"
using namespace std;

#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;

const int MXN = 1005;
vector<int> edge[MXN];
set<pii> S;

void BSH(vector<int> v, int x) {
    auto check = [&]() -> bool {
        v.push_back(x);
        bool f = (Query(v) != v.size());
        v.pop_back();
        return f;
    };
    do {
        int l = 0, r = v.size();
        while (l + 1 < r) {
            int mid = (l + r) >> 1;
            // printf("%d %d\n", l, r);
            vector<int> w(mid);
            copy(v.begin(), v.begin() + mid, w.begin());
            w.push_back(x);
            (Query(w) != w.size() ? r : l) = mid;
        }
        edge[x].push_back(v[l]);
        edge[v[l]].push_back(x);
        S.insert(mp(min(x, v[l]), max(x, v[l])));
        v.erase(v.begin() + l);
    } while (check());
}

void DO(vector<int> &v) {
    if (v.empty()) return;
    vector<int> a, b;
    for (auto &i : v) {
        a.push_back(i);
        if (Query(a) < a.size()) {
            a.pop_back();
            b.push_back(i);
        }
    }
    for (auto &i : b) BSH(a, i);
    DO(b);
}

void KILL(int id) {
    auto f = [&](int id, int a, int b) -> int {
        vector<int> v{id, a, b};
        return Query(v);
    };
    auto g = [&](int id, int a, int b, int c) -> int {
        if (f(id, a, b) == 1) return c;
        if (f(id, b, c) == 1) return a;
        return b;
    };
    if (edge[id].size() == 1) return;
    int a = edge[id][0], b = edge[id][1], c = edge[id][2];
    int d = g(id, a, b, c);
    if (id > d) swap(id, d);
    S.erase(mp(id, d));
}

void Solve(int n) {
    int N = n * 2;
    vector<int> v;
    FOR(i, 1, N + 1) v.push_back(i);
    DO(v);
    FOR(i, 1, N + 1) KILL(i);
    for (auto i : S) Answer(i.fs, i.sc);
}

Compilation message

chameleon.cpp: In lambda function:
chameleon.cpp:18:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         bool f = (Query(v) != v.size());
      |                   ~~~~~~~~~^~~~~~~~~~~
chameleon.cpp: In function 'void BSH(std::vector<int>, int)':
chameleon.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |             (Query(w) != w.size() ? r : l) = mid;
      |              ~~~~~~~~~^~~~~~~~~~~
chameleon.cpp: In function 'void DO(std::vector<int>&)':
chameleon.cpp:44:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         if (Query(a) < a.size()) {
      |             ~~~~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 13 ms 568 KB Output is correct
4 Correct 13 ms 344 KB Output is correct
5 Correct 13 ms 344 KB Output is correct
6 Correct 13 ms 576 KB Output is correct
7 Correct 13 ms 564 KB Output is correct
8 Correct 13 ms 344 KB Output is correct
9 Correct 15 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 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 1 ms 344 KB Output is correct
7 Correct 0 ms 392 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 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 1 ms 344 KB Output is correct
7 Correct 0 ms 392 KB Output is correct
8 Correct 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 32 ms 536 KB Output is correct
4 Correct 39 ms 572 KB Output is correct
5 Correct 31 ms 600 KB Output is correct
6 Correct 32 ms 600 KB Output is correct
7 Correct 31 ms 600 KB Output is correct
8 Correct 33 ms 588 KB Output is correct
9 Correct 38 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 13 ms 568 KB Output is correct
4 Correct 13 ms 344 KB Output is correct
5 Correct 13 ms 344 KB Output is correct
6 Correct 13 ms 576 KB Output is correct
7 Correct 13 ms 564 KB Output is correct
8 Correct 13 ms 344 KB Output is correct
9 Correct 15 ms 344 KB Output is correct
10 Correct 0 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 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 392 KB Output is correct
17 Correct 0 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 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 32 ms 536 KB Output is correct
31 Correct 39 ms 572 KB Output is correct
32 Correct 31 ms 600 KB Output is correct
33 Correct 32 ms 600 KB Output is correct
34 Correct 31 ms 600 KB Output is correct
35 Correct 33 ms 588 KB Output is correct
36 Correct 38 ms 600 KB Output is correct
37 Correct 29 ms 600 KB Output is correct
38 Correct 13 ms 344 KB Output is correct
39 Correct 28 ms 604 KB Output is correct
40 Correct 29 ms 600 KB Output is correct
41 Correct 28 ms 592 KB Output is correct
42 Correct 13 ms 344 KB Output is correct
43 Correct 31 ms 572 KB Output is correct
44 Correct 28 ms 600 KB Output is correct
45 Correct 28 ms 600 KB Output is correct