답안 #448555

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
448555 2021-07-30T16:11:21 Z JooDdae 카멜레온의 사랑 (JOI20_chameleon) C++17
4 / 100
51 ms 768 KB
#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;

int nxt[1010];
bool chk[1010];
vector<int> v[1010];

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() ? -1 : R;
}

void addEdge(int a, int b){
    v[a].push_back(b), v[b].push_back(a);
}

void find(int u, const vector<int> &x){
    if(x.size() <= 1) return;

    int bf = 1;
    for(int i=0;i<3;i++){
        int A = lb(u, x, bf);
        if(A < 0) return;
        addEdge(u, x[A+1]), bf = A+2;
    }
}

void solve2(const vector<int> &g, const vector<int> &b){
    vector<int> k = g;
    for(int u : b){
        while(!k.empty() && k[0] < u){
            reverse(k.begin(), k.end()), k.pop_back(), reverse(k.begin(), k.end());
        }
        reverse(k.begin(), k.end()), k.push_back(u), reverse(k.begin(), k.end());
        find(u, k);
        reverse(k.begin(), k.end()), k.pop_back(), reverse(k.begin(), k.end());
    }
}

void Solve(int N) {
    set<int> s;

    for(int i=1;i<=2*N;i++){
        s.insert(i);
        vector<int> q(s.begin(), s.end());

        if(Query(q) != q.size()){
            reverse(q.begin(), q.end());
            find(i, q);

            if(v[i].size() == 3){
                s.erase(i);
            }else{
                for(auto x : v[i]) s.erase(x);
            }
        }
    }

    vector<int> chk2(2*N+1);

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

        solve2(g, b);
    }

    // for(int i=1;i<=2*N;i++){
    //     printf("[%d] :",i);
    //     for(int x : v[i]) printf(" %d",x);
    //     puts("");
    // }

    for(int i=1;i<=2*N;i++) if(!chk[i]){
        if(v[i].size() == 1){
            chk[i] = chk[v[i][0]] = 1, Answer(i, v[i][0]);
            continue;
        }

        int &A = v[i][0], &B = v[i][1], &C = v[i][2];
        if(Query({i, B, C}) == 1) swap(A, C);
        else if(Query({i, A, C}) == 1) swap(B, C);
        nxt[i] = C, v[i].pop_back();
    }

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

Compilation message

chameleon.cpp: In function 'int lb(int, const std::vector<int>&, int)':
chameleon.cpp:18:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         if(Query(Q) == Q.size()) L = M+1;
      |            ~~~~~~~~~^~~~~~~~~~~
chameleon.cpp:22:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     return L == x.size() ? -1 : R;
      |            ~~^~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:59:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         if(Query(q) != q.size()){
      |            ~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 47 ms 396 KB Output is correct
4 Correct 48 ms 768 KB Output is correct
5 Correct 46 ms 392 KB Output is correct
6 Correct 45 ms 404 KB Output is correct
7 Correct 45 ms 408 KB Output is correct
8 Correct 48 ms 492 KB Output is correct
9 Correct 46 ms 404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 328 KB Output is correct
2 Incorrect 0 ms 328 KB Wrong Answer [6]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 328 KB Output is correct
2 Incorrect 0 ms 328 KB Wrong Answer [6]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Incorrect 51 ms 396 KB Wrong Answer [1]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 47 ms 396 KB Output is correct
4 Correct 48 ms 768 KB Output is correct
5 Correct 46 ms 392 KB Output is correct
6 Correct 45 ms 404 KB Output is correct
7 Correct 45 ms 408 KB Output is correct
8 Correct 48 ms 492 KB Output is correct
9 Correct 46 ms 404 KB Output is correct
10 Correct 0 ms 328 KB Output is correct
11 Incorrect 0 ms 328 KB Wrong Answer [6]
12 Halted 0 ms 0 KB -