답안 #582712

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
582712 2022-06-24T10:31:51 Z elkernos 카멜레온의 사랑 (JOI20_chameleon) C++17
100 / 100
65 ms 540 KB
#include "chameleon.h"
#include <bits/stdc++.h>

using namespace std;

void Solve(int n)
{
    n = 2 * n;
    vector<int> nxt(n + 1);
    vector<vector<int>> g(n + 1);
    int used = 0;
    for(int i = 1; i <= n; i++) {
        int dorzuc = -1;
        vector<int> col(i, -1);
        function<void(int, bool)> dfs = [&](int u, bool newcol) {
            col[u] = newcol;
            for(int to : g[u]) {
                if(col[to] == -1) {
                    dfs(to, !newcol);
                }
            }
        };
        vector<vector<int>> zbio(2);
        for(int j = 1; j < i; j++) {
            if(col[j] == -1) {
                dfs(j, 0);
            }
            zbio[col[j]].push_back(j);
        }
        for(int j = 0; j < 2; j++) {
            int gdz = 0;
            auto pyt = [&](int ii, int a, int b, int add) {
                vector<int> q;
                for(int i = a; i <= b; i++) {
                    q.push_back(zbio[ii][i]);
                }
                q.push_back(add);
                return Query(q) != (int)q.size();
            };
            while(gdz < (int)zbio[j].size() && pyt(j, gdz, (int)zbio[j].size() - 1, i)) {
                int lo = gdz, hi = (int)zbio[j].size() - 1, ans = -1;
                while(lo <= hi) {
                    int m = (lo + hi) / 2;
                    if(pyt(j, gdz, m, i)) {
                        ans = m;
                        hi = m - 1;
                    }
                    else {
                        lo = m + 1;
                    }
                }
                assert(ans != -1);
                g[i].push_back(zbio[j][ans]);
                g[zbio[j][ans]].push_back(i);
                gdz = ans + 1;
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        if((int)g[i].size() == 1) {
            continue;
        }
        vector<vector<int>> pytaj = {{i, g[i][0], g[i][1]},
                                     {i, g[i][0], g[i][2]},
                                     {i, g[i][1], g[i][2]}};
        random_shuffle(pytaj.begin(), pytaj.end());
        vector<int> all = {i, g[i][0], g[i][1], g[i][2]};
        for(vector<int> pyt : pytaj) {
            if(Query(pyt) == 1) {
                for(int ii : all) {
                    if(find(pyt.begin(), pyt.end(), ii) == pyt.end()) {
                        nxt[i] = ii;
                    }
                }
                break;
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        int ans = -1;
        for(int x : g[i]) {
            if(x != nxt[i] && nxt[x] != i) {
                ans = x;
            }
        }
        assert(ans != -1);
        if(ans > i) {
            Answer(i, ans);
        }
    }
}

Compilation message

chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:13:13: warning: unused variable 'dorzuc' [-Wunused-variable]
   13 |         int dorzuc = -1;
      |             ^~~~~~
chameleon.cpp:11:9: warning: unused variable 'used' [-Wunused-variable]
   11 |     int used = 0;
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 37 ms 396 KB Output is correct
4 Correct 39 ms 396 KB Output is correct
5 Correct 38 ms 360 KB Output is correct
6 Correct 36 ms 400 KB Output is correct
7 Correct 36 ms 392 KB Output is correct
8 Correct 36 ms 388 KB Output is correct
9 Correct 34 ms 408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 60 ms 540 KB Output is correct
4 Correct 65 ms 480 KB Output is correct
5 Correct 59 ms 392 KB Output is correct
6 Correct 53 ms 396 KB Output is correct
7 Correct 54 ms 400 KB Output is correct
8 Correct 56 ms 420 KB Output is correct
9 Correct 57 ms 424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 37 ms 396 KB Output is correct
4 Correct 39 ms 396 KB Output is correct
5 Correct 38 ms 360 KB Output is correct
6 Correct 36 ms 400 KB Output is correct
7 Correct 36 ms 392 KB Output is correct
8 Correct 36 ms 388 KB Output is correct
9 Correct 34 ms 408 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 0 ms 208 KB Output is correct
16 Correct 0 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 0 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 1 ms 208 KB Output is correct
21 Correct 1 ms 208 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 1 ms 208 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 208 KB Output is correct
27 Correct 1 ms 208 KB Output is correct
28 Correct 0 ms 208 KB Output is correct
29 Correct 0 ms 208 KB Output is correct
30 Correct 60 ms 540 KB Output is correct
31 Correct 65 ms 480 KB Output is correct
32 Correct 59 ms 392 KB Output is correct
33 Correct 53 ms 396 KB Output is correct
34 Correct 54 ms 400 KB Output is correct
35 Correct 56 ms 420 KB Output is correct
36 Correct 57 ms 424 KB Output is correct
37 Correct 58 ms 532 KB Output is correct
38 Correct 37 ms 336 KB Output is correct
39 Correct 54 ms 336 KB Output is correct
40 Correct 65 ms 436 KB Output is correct
41 Correct 54 ms 408 KB Output is correct
42 Correct 37 ms 392 KB Output is correct
43 Correct 59 ms 520 KB Output is correct
44 Correct 60 ms 432 KB Output is correct
45 Correct 63 ms 388 KB Output is correct