답안 #372453

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
372453 2021-02-28T08:39:54 Z KoD 카멜레온의 사랑 (JOI20_chameleon) C++17
40 / 100
46 ms 4332 KB
#include <bits/stdc++.h>
#include "chameleon.h"

template <class T>
using Vec = std::vector<T>;

void Solve(int N) {
    Vec<Vec<int>> graph(2 * N + 1);
    if (N <= 50) {
        for (int u = 1; u <= 2 * N; ++u) {
            for (int v = u + 1; v <= 2 * N; ++v) {
                const auto kinds = Query({ u, v });
                if (kinds == 1) {
                    graph[u].push_back(v);
                    graph[v].push_back(u);
                }
            }
        }
    }
    else {
        std::random_device dev;
        std::default_random_engine gen(dev() ^ std::clock());
        for (int u = 1; u <= N; ++u) {
            const auto dif = [&](Vec<int> vec) {
                vec.push_back(u);
                return (int) vec.size() - Query(vec);
            };
            std::queue<std::pair<Vec<int>, int>> que;
            {
                Vec<int> cand(N);
                std::iota(cand.begin(), cand.end(), N + 1);
                que.emplace(cand, dif(cand));
            }
            while (!que.empty()) {
                auto [vec, d] = que.front();
                que.pop();
                if (vec.size() == 1) {
                    const auto v = vec.front();
                    graph[u].push_back(v);
                    graph[v].push_back(u);
                    continue;
                }
                std::shuffle(vec.begin(), vec.end(), gen);
                Vec<int> left(vec.begin(), vec.begin() + vec.size() / 2);
                Vec<int> right(vec.begin() + vec.size() / 2, vec.end());
                const auto l = dif(left);
                if (l == 0) {
                    que.emplace(right, d);
                }
                else {
                    que.emplace(left, l);
                    const auto r = dif(right);
                    if (r != 0) {
                        que.emplace(right, r);
                    }
                }
            }
        }
    }
    Vec<Vec<int>> prob(2 * N + 1, Vec<int>(2 * N + 1));
    for (int u = 1; u <= 2 * N; ++u) {
        if (graph[u].size() == 1) {
            prob[u][graph[u].front()] = true;
        }
        else {
            assert(graph[u].size() == 3);
            for (int ignore = 0; ignore < 3; ++ignore) {
                if (prob[graph[u][ignore]][u] == 2) {
                    continue;
                }
                Vec<int> ask;
                ask.push_back(u);
                for (int k = 0; k < 3; ++k) {
                    if (ignore != k) {
                        ask.push_back(graph[u][k]);
                    }
                }
                if (Query(ask) == 2) {
                    prob[u][graph[u][ignore]] = 1;
                }
                else {
                    prob[u][graph[u][ignore]] = 2;
                }
            }
        }
    }
    for (int u = 1; u <= 2 * N; ++u) {
        for (int v = u + 1; v <= 2 * N; ++v) {
            if (prob[u][v] == 1 && prob[v][u] == 1) {
                Answer(u, v);
            }
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Incorrect 42 ms 364 KB Wrong Answer [3]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 380 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 46 ms 4332 KB Wrong Answer [3]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Incorrect 42 ms 364 KB Wrong Answer [3]
4 Halted 0 ms 0 KB -