Submission #448502

# Submission time Handle Problem Language Result Execution time Memory
448502 2021-07-30T10:28:39 Z JooDdae Chameleon's Love (JOI20_chameleon) C++17
0 / 100
41 ms 360 KB
#include "chameleon.h"
#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);

    v[A].push_back(u), v[B].push_back(u), v[C].push_back(u);
}
 
void Solve(int N) {
    nxt.resize(2*N+1), v.resize(2*N+1);
 
    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);
 
        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 : v2[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[i] = 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);
 
        vector<bool> chk(2*N+1);
 
        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=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[i] = chk[x] = 1, Answer(i, x);
        }
    }
}

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;
      |            ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Incorrect 32 ms 360 KB Wrong Answer [1]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 220 KB Output is correct
2 Incorrect 0 ms 200 KB Wrong Answer [6]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 220 KB Output is correct
2 Incorrect 0 ms 200 KB Wrong Answer [6]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Incorrect 41 ms 348 KB Wrong Answer [1]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Incorrect 32 ms 360 KB Wrong Answer [1]
4 Halted 0 ms 0 KB -