답안 #448104

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

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

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

namespace subtask3{
    bool HasEdge(int u, int v){
        return Query({ u, v }) == 1;
    }

    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;
    }

    void Solve(){
        for(int i=1; i<=N; i++){
            for(int j=1; j<i; j++){
                if(HasEdge(i, j)) G[i].push_back(j), G[j].push_back(i);
            }
        }
        for(int i=1; i<=N; i++){
            if(G[i].size() == 1){
                Match[i] = G[i][0];
                Match[G[i][0]] = i;
                continue;
            }
            auto 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]);
    }
}

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

    void Solve(){
        vector<int> vec;
        for(int i=1; i<=N; i++){
            if(vec.empty() || !HasSameColor(vec, i)){ vec.push_back(i); continue; }
            int l = 0, r = vec.size() - 1;
            while(l < r){
                int m = l + r >> 1;
                vector<int> now(1, i);
                for(int j=0; j<=m; j++) now.push_back(vec[j]);
                if(Query(now) < now.size()) r = m;
                else l = m + 1;
            }
            Answer(vec[l], i);
            vec.erase(vec.begin() + l);
        }
    }
}

void Solve(int n){
    N = n + n; Init();
    if(n <= 50){ subtask3::Solve(); return; }
    subtask1::Solve();
}

Compilation message

chameleon.cpp: In function 'bool subtask1::HasSameColor(std::vector<int>, int)':
chameleon.cpp:55:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         return Query(vec) < vec.size();
      |                ~~~~~~~~~~~^~~~~~~~~~~~
chameleon.cpp: In function 'void subtask1::Solve()':
chameleon.cpp:64:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   64 |                 int m = l + r >> 1;
      |                         ~~^~~
chameleon.cpp:67:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |                 if(Query(now) < now.size()) r = m;
      |                    ~~~~~~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1224 KB Output is correct
2 Correct 1 ms 1224 KB Output is correct
3 Correct 13 ms 1352 KB Output is correct
4 Correct 13 ms 1368 KB Output is correct
5 Correct 17 ms 1352 KB Output is correct
6 Correct 12 ms 1352 KB Output is correct
7 Correct 13 ms 1352 KB Output is correct
8 Correct 13 ms 1352 KB Output is correct
9 Correct 13 ms 1376 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 2 ms 1224 KB Output is correct
12 Correct 3 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 2 ms 1224 KB Output is correct
16 Correct 2 ms 1224 KB Output is correct
17 Correct 2 ms 1224 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 Incorrect 3 ms 1352 KB Wrong Answer [6]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1224 KB Output is correct
2 Correct 1 ms 1224 KB Output is correct
3 Correct 13 ms 1352 KB Output is correct
4 Correct 13 ms 1368 KB Output is correct
5 Correct 17 ms 1352 KB Output is correct
6 Correct 12 ms 1352 KB Output is correct
7 Correct 13 ms 1352 KB Output is correct
8 Correct 13 ms 1352 KB Output is correct
9 Correct 13 ms 1376 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 2 ms 1224 KB Output is correct
21 Correct 3 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 2 ms 1224 KB Output is correct
25 Correct 2 ms 1224 KB Output is correct
26 Correct 2 ms 1224 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 Incorrect 3 ms 1352 KB Wrong Answer [6]
31 Halted 0 ms 0 KB -