답안 #448510

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
448510 2021-07-30T10:38:01 Z JooDdae 카멜레온의 사랑 (JOI20_chameleon) C++17
0 / 100
31 ms 352 KB
#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
 
vector<int> nxt, chk;
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);
 
    A = x[A+1], B = x[B+1], C = x[C+1];
 
    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);

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

void solve2(vector<int> &g, vector<int> &b){
    for(int u : b){
        find(u, g);
        if(v[u].size() == 1){
            chk[u] = chk[v[u][0]] = 1, Answer(u, v[u][0]);
        }
    }

    for(int u : g) if(!chk[u]){
        int A = v[u][0], B = v[u][1], C = v[u][2]; v[u].clear();

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

    for(int i : g) if(!chk[i]){
        int x = (v[i].size() == 1 || nxt[v[i][1]] == i ? v[i][0] : v[i][1]);
        Answer(i, x);
    }
}

void Solve(int N) {
    nxt.resize(2*N+1), v.resize(2*N+1), chk.resize(2*N+1);
    vector<int> g, b;
 
    if(N <= 50){
        vector<int> v2[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) v2[i].push_back(j), v2[j].push_back(i);

        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 : v2[u]) if(!chk[x]) chk[x] = 1, q.push({x, !c});
            }
 
            solve2(g, b);
            b.clear(), g.clear();
        }
    }else{
        for(int i=1;i<=N;i++) b.push_back(i), g.push_back(N+i);
        solve2(g, b);
    }
}

Compilation message

chameleon.cpp: In function 'int lb(int, const std::vector<int>&, int)':
chameleon.cpp:17:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |         if(Query(Q) == Q.size()) L = M+1;
      |            ~~~~~~~~~^~~~~~~~~~~
chameleon.cpp:21:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     return L == x.size() ? -2 : R;
      |            ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Incorrect 31 ms 352 KB Wrong Answer [1]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Incorrect 0 ms 200 KB Wrong Answer [7]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Incorrect 0 ms 200 KB Wrong Answer [7]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Incorrect 0 ms 200 KB Wrong Answer [7]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Incorrect 31 ms 352 KB Wrong Answer [1]
4 Halted 0 ms 0 KB -