답안 #448142

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
448142 2021-07-29T03:27:51 Z jhnah917 카멜레온의 사랑 (JOI20_chameleon) C++14
100 / 100
94 ms 1528 KB
#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;

namespace {
    int N, Match[1010], Color[1010];
    bool Love[1010][1010];
    vector<int> G[1010], Nodes[2];

    void Init(){
        memset(Match, -1, sizeof Match);
        memset(Color, -1, sizeof Color);
        memset(Love, 0, sizeof Love);
        for(int i=0; i<1010; i++) G[i].clear();
    }

    void DFS(int v, int color){
        Color[v] = color; Nodes[color].push_back(v);
        for(auto i : G[v]) if(Color[i] == -1) DFS(i, color^1);
    }

    bool HasEdge(vector<int> vec, int now){
        vec.push_back(now);
        return Query(vec) < vec.size();
    }

    int Search(const vector<int> &vec, int v){
        int l = 0, r = vec.size() - 1;
        while(l < r){
            int m = l + r >> 1;
            vector<int> now;
            for(int i=0; i<=m; i++) now.push_back(vec[i]);
            if(HasEdge(now, v)) r = m;
            else l = m + 1;
        }
        return r;
    }

    int Like(int v){
        int a = G[v][0], b = G[v][1], c = G[v][2];
        if(Query({ v, b, c }) == 1) return a;
        if(Query({ v, a, c }) == 1) return b;
        return c;
    }
}  // namespace

void Solve(int n){
    N = n + n; Init();
    for(int i=1; i<=N; i++){
        memset(Color, -1, sizeof Color);
        Nodes[0].clear(); Nodes[1].clear();
        for(int j=1; j<i; j++) if(Color[j] == -1) DFS(j, 0);

        for(int c=0; c<2; c++){
            while(HasEdge(Nodes[c], i)){
                auto j = Search(Nodes[c], i);
                G[i].push_back(Nodes[c][j]);
                G[Nodes[c][j]].push_back(i);
                Nodes[c].erase(Nodes[c].begin() + j);
            }
        }
    }

    for(int i=1; i<=N; i++){
        if(G[i].size() == 1){
            Match[i] = G[i][0];
            Match[G[i][0]] = i;
            continue;
        }
        int j = Like(i);
        Love[i][j] = Love[j][i] = true;
    }

    for(int i=1; i<=N; i++){
        if(Match[i] != -1) continue;
        for(auto j : G[i]) if(!Love[i][j]) Match[i] = j;
    }
    for(int i=1; i<=N; i++) if(i < Match[i]) Answer(i, Match[i]);
}

Compilation message

chameleon.cpp: In function 'bool {anonymous}::HasEdge(std::vector<int>, int)':
chameleon.cpp:24:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         return Query(vec) < vec.size();
      |                ~~~~~~~~~~~^~~~~~~~~~~~
chameleon.cpp: In function 'int {anonymous}::Search(const std::vector<int>&, int)':
chameleon.cpp:30:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |             int m = l + r >> 1;
      |                     ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1224 KB Output is correct
2 Correct 1 ms 1224 KB Output is correct
3 Correct 34 ms 1400 KB Output is correct
4 Correct 37 ms 1400 KB Output is correct
5 Correct 35 ms 1400 KB Output is correct
6 Correct 37 ms 1352 KB Output is correct
7 Correct 34 ms 1388 KB Output is correct
8 Correct 35 ms 1392 KB Output is correct
9 Correct 36 ms 1396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1224 KB Output is correct
2 Correct 1 ms 1224 KB Output is correct
3 Correct 1 ms 1224 KB Output is correct
4 Correct 1 ms 1224 KB Output is correct
5 Correct 1 ms 1224 KB Output is correct
6 Correct 1 ms 1224 KB Output is correct
7 Correct 1 ms 1224 KB Output is correct
8 Correct 1 ms 1224 KB Output is correct
9 Correct 1 ms 1224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1224 KB Output is correct
2 Correct 1 ms 1224 KB Output is correct
3 Correct 1 ms 1224 KB Output is correct
4 Correct 1 ms 1224 KB Output is correct
5 Correct 1 ms 1224 KB Output is correct
6 Correct 1 ms 1224 KB Output is correct
7 Correct 1 ms 1224 KB Output is correct
8 Correct 1 ms 1224 KB Output is correct
9 Correct 1 ms 1224 KB Output is correct
10 Correct 2 ms 1224 KB Output is correct
11 Correct 1 ms 1224 KB Output is correct
12 Correct 2 ms 1224 KB Output is correct
13 Correct 2 ms 1224 KB Output is correct
14 Correct 2 ms 1224 KB Output is correct
15 Correct 1 ms 1224 KB Output is correct
16 Correct 2 ms 1352 KB Output is correct
17 Correct 2 ms 1352 KB Output is correct
18 Correct 2 ms 1224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1224 KB Output is correct
2 Correct 1 ms 1224 KB Output is correct
3 Correct 94 ms 1440 KB Output is correct
4 Correct 92 ms 1352 KB Output is correct
5 Correct 93 ms 1512 KB Output is correct
6 Correct 92 ms 1384 KB Output is correct
7 Correct 94 ms 1352 KB Output is correct
8 Correct 93 ms 1384 KB Output is correct
9 Correct 91 ms 1388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1224 KB Output is correct
2 Correct 1 ms 1224 KB Output is correct
3 Correct 34 ms 1400 KB Output is correct
4 Correct 37 ms 1400 KB Output is correct
5 Correct 35 ms 1400 KB Output is correct
6 Correct 37 ms 1352 KB Output is correct
7 Correct 34 ms 1388 KB Output is correct
8 Correct 35 ms 1392 KB Output is correct
9 Correct 36 ms 1396 KB Output is correct
10 Correct 1 ms 1224 KB Output is correct
11 Correct 1 ms 1224 KB Output is correct
12 Correct 1 ms 1224 KB Output is correct
13 Correct 1 ms 1224 KB Output is correct
14 Correct 1 ms 1224 KB Output is correct
15 Correct 1 ms 1224 KB Output is correct
16 Correct 1 ms 1224 KB Output is correct
17 Correct 1 ms 1224 KB Output is correct
18 Correct 1 ms 1224 KB Output is correct
19 Correct 2 ms 1224 KB Output is correct
20 Correct 1 ms 1224 KB Output is correct
21 Correct 2 ms 1224 KB Output is correct
22 Correct 2 ms 1224 KB Output is correct
23 Correct 2 ms 1224 KB Output is correct
24 Correct 1 ms 1224 KB Output is correct
25 Correct 2 ms 1352 KB Output is correct
26 Correct 2 ms 1352 KB Output is correct
27 Correct 2 ms 1224 KB Output is correct
28 Correct 1 ms 1224 KB Output is correct
29 Correct 1 ms 1224 KB Output is correct
30 Correct 94 ms 1440 KB Output is correct
31 Correct 92 ms 1352 KB Output is correct
32 Correct 93 ms 1512 KB Output is correct
33 Correct 92 ms 1384 KB Output is correct
34 Correct 94 ms 1352 KB Output is correct
35 Correct 93 ms 1384 KB Output is correct
36 Correct 91 ms 1388 KB Output is correct
37 Correct 87 ms 1404 KB Output is correct
38 Correct 35 ms 1352 KB Output is correct
39 Correct 83 ms 1432 KB Output is correct
40 Correct 90 ms 1396 KB Output is correct
41 Correct 92 ms 1528 KB Output is correct
42 Correct 35 ms 1396 KB Output is correct
43 Correct 93 ms 1352 KB Output is correct
44 Correct 86 ms 1524 KB Output is correct
45 Correct 87 ms 1436 KB Output is correct