답안 #213316

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
213316 2020-03-25T13:57:14 Z popovicirobert 카멜레온의 사랑 (JOI20_chameleon) C++14
100 / 100
89 ms 888 KB
#include "chameleon.h"
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1000;

static vector<int> g[MAXN + 1];
static vector<int> side[2];
static bool vis[MAXN + 1];

void dfs(int nod, int col) {
    if(vis[nod]) return ;
    vis[nod] = 1;
    side[col].push_back(nod);
    for(auto it : g[nod]) {
        dfs(it, col ^ 1);
    }
}

void Solve(int n) {
    vector<set<int>> all(2 * n + 1);
    for(int i = 1; i <= 2 * n; i++) {
        for(int t = 0; t < 2; t++) {
            int x = -1, sz = side[t].size();
            while(x < sz && g[i].size() < 3) {
                vector<int> cur;
                cur.push_back(i);
                for(int j = x + 1; j < sz; j++) {
                    cur.push_back(side[t][j]);
                }
                if(Query(cur) == cur.size()) {
                    break;
                }
                int y = x;
                for(int step = 1 << 9; step; step >>= 1) {
                    if(y + step < sz) {
                        vector<int> cur;
                        cur.push_back(i);
                        for(int j = x + 1; j <= y + step; j++) {
                            cur.push_back(side[t][j]);
                        }
                        if(Query(cur) == cur.size()) {
                            y += step;
                        }
                    }
                }
                y++;
                if(y < sz) {
                    all[i].insert(side[t][y]);
                    all[side[t][y]].insert(i);
                    g[i].push_back(side[t][y]);
                    g[side[t][y]].push_back(i);
                }
                x = y;
            }
            side[t].clear();
        }
        fill(vis, vis + i + 1, 0);
        for(int j = 1; j <= i; j++) {
            dfs(j, 0);
        }
    }
    for(int i = 1; i <= 2 * n; i++) {
        g[i].clear();
    }
    for(int i = 1; i <= 2 * n; i++) {
        vector<int> cur;
        for(auto it : all[i]) {
            cur.push_back(it);
        }
        int j;
        if(cur.size() == 3) {
            if(Query({i, cur[0], cur[1]}) == 1) {
                j = cur[2];
            }
            else if(Query({i, cur[1], cur[2]}) == 1) {
                j = cur[0];
            }
            else {
                j = cur[1];
            }
            g[i].push_back(j);
            g[j].push_back(i);
        }
    }
    for(int i = 1; i <= 2 * n; i++) {
        for(auto it : g[i]) {
            if(all[i].count(it)) {
                all[i].erase(it);
            }
        }
        assert(all[i].size() == 1);
        if(*all[i].begin() > i) {
            Answer(i, *all[i].begin());
        }
    }
}


Compilation message

chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:32:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if(Query(cur) == cur.size()) {
                    ~~~~~~~~~~~^~~~~~~~~~~~~
chameleon.cpp:43:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                         if(Query(cur) == cur.size()) {
                            ~~~~~~~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 44 ms 512 KB Output is correct
4 Correct 47 ms 512 KB Output is correct
5 Correct 44 ms 512 KB Output is correct
6 Correct 47 ms 512 KB Output is correct
7 Correct 47 ms 504 KB Output is correct
8 Correct 44 ms 512 KB Output is correct
9 Correct 44 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 5 ms 432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 83 ms 608 KB Output is correct
4 Correct 80 ms 632 KB Output is correct
5 Correct 81 ms 632 KB Output is correct
6 Correct 80 ms 636 KB Output is correct
7 Correct 80 ms 632 KB Output is correct
8 Correct 80 ms 632 KB Output is correct
9 Correct 81 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 44 ms 512 KB Output is correct
4 Correct 47 ms 512 KB Output is correct
5 Correct 44 ms 512 KB Output is correct
6 Correct 47 ms 512 KB Output is correct
7 Correct 47 ms 504 KB Output is correct
8 Correct 44 ms 512 KB Output is correct
9 Correct 44 ms 512 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 7 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 6 ms 384 KB Output is correct
27 Correct 5 ms 432 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 83 ms 608 KB Output is correct
31 Correct 80 ms 632 KB Output is correct
32 Correct 81 ms 632 KB Output is correct
33 Correct 80 ms 636 KB Output is correct
34 Correct 80 ms 632 KB Output is correct
35 Correct 80 ms 632 KB Output is correct
36 Correct 81 ms 632 KB Output is correct
37 Correct 84 ms 632 KB Output is correct
38 Correct 44 ms 496 KB Output is correct
39 Correct 83 ms 632 KB Output is correct
40 Correct 87 ms 684 KB Output is correct
41 Correct 83 ms 632 KB Output is correct
42 Correct 45 ms 512 KB Output is correct
43 Correct 80 ms 632 KB Output is correct
44 Correct 83 ms 632 KB Output is correct
45 Correct 89 ms 888 KB Output is correct