답안 #448102

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
448102 2021-07-29T02:17:15 Z jhnah917 카멜레온의 사랑 (JOI20_chameleon) C++14
0 / 100
1 ms 1224 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<N; 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 Incorrect 1 ms 1224 KB Wrong Answer [2]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1224 KB Wrong Answer [2]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1224 KB Wrong Answer [2]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1224 KB Wrong Answer [2]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1224 KB Wrong Answer [2]
2 Halted 0 ms 0 KB -