답안 #448457

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
448457 2021-07-30T08:27:46 Z JooDdae 카멜레온의 사랑 (JOI20_chameleon) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> b, g, nxt;
vector<vector<int>> v;

int lb(int u, const vector<int> &x, int l){

    int L = l, R = x.size()-1;
    while(L <= R){
        int M = (L+R)/2;

        vector<int> Q(1, u);
        for(int i=l;i<=M;i++) Q.push_back(x[i]);

        if(Query(Q) == Q.size()) L = M+1;
        else R = M-1;
    }

    return L == x.size() ? -2 : R;
}

void find(int u, const vector<int> &x){
    int A = lb(u, x, 0);
    int B = lb(u, x, A+2);

    if(B < -1){
        v[u].push_back(x[A+1]);
        return;
    }

    int C = lb(u, x, B+2);

    // cout << A << " " << B << " " << C << "\n";
    A = x[A+1], B = x[B+1], C = x[C+1];
    // cout << A << " " << B << " " << C << "\n";

    if(Query({u, B, C}) == 1){
        swap(A, C);
    }else if(Query({u, A, C}) == 1){
        swap(B, C);
    }

    nxt[u] = C;
    v[u].push_back(A), v[u].push_back(B);
}

void Solve(int N) {
    nxt.resize(2*N+1), v.resize(2*N+1);

    if(N <= 50){
        vector<int> v[2*N+1];
        for(int i=1;i<=2*N;i++) for(int j=i+1;j<=2*N;j++) if(Query({i, j}) == 1) v[i].push_back(j), v[j].push_back(i);

        vector<bool> chk(2*N+1), chk2(2*N+1);
        for(int i=1;i<=2*N;i++) if(!chk[i]){
            vector<int> nodes;

            queue<pair<int, int>> q; chk[i] = 1, q.push({i, 0});
            while(!q.empty()){
                auto [u, c] = q.front(); q.pop();
                nodes.push_back(u);
                (c ? b : g).push_back(u);
                for(auto x : v[u]) if(!chk[x]) chk[x] = 1, q.push({x, !c});
            }

            for(int u : b) find(u, g);
            for(int u : g) find(u, b);

            for(int i : nodes) if(!chk2[i]) {
                int x = (v[i].size() == 1 || chk2[v[i][1]] || nxt[v[i][1]] == i? v[i][0] : v[i][1]);
                chk2[x] = 1, Answer(i, x);
            }
            b.clear(), g.clear();
        }
    }else{
        for(int i=1;i<=N;i++) b.push_back(i), g.push_back(N+i);
        for(int u : b) find(u, g);
        for(int u : g) find(u, b);

        vector<bool> chk(2*N+1);
        for(int i=1;i<=2*N;i++) if(!chk[i]) {
            int x = (v[i].size() == 1 || chk[v[i][1]] || nxt[v[i][1]] == i? v[i][0] : v[i][1]);
            chk[x] = 1, Answer(i, x);
        }
    }
}

Compilation message

chameleon.cpp: In function 'int lb(int, const std::vector<int>&, int)':
chameleon.cpp:16:12: error: 'Query' was not declared in this scope
   16 |         if(Query(Q) == Q.size()) L = M+1;
      |            ^~~~~
chameleon.cpp:20:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     return L == x.size() ? -2 : R;
      |            ~~^~~~~~~~~~~
chameleon.cpp: In function 'void find(int, const std::vector<int>&)':
chameleon.cpp:38:8: error: 'Query' was not declared in this scope
   38 |     if(Query({u, B, C}) == 1){
      |        ^~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:53:62: error: 'Query' was not declared in this scope
   53 |         for(int i=1;i<=2*N;i++) for(int j=i+1;j<=2*N;j++) if(Query({i, j}) == 1) v[i].push_back(j), v[j].push_back(i);
      |                                                              ^~~~~
chameleon.cpp:72:30: error: 'Answer' was not declared in this scope
   72 |                 chk2[x] = 1, Answer(i, x);
      |                              ^~~~~~
chameleon.cpp:84:25: error: 'Answer' was not declared in this scope
   84 |             chk[x] = 1, Answer(i, x);
      |                         ^~~~~~