답안 #938221

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938221 2024-03-05T02:59:08 Z guagua0407 카멜레온의 사랑 (JOI20_chameleon) C++17
100 / 100
54 ms 1032 KB
#include "chameleon.h"
#include<bits/stdc++.h>

namespace {

using namespace std;
#define all(x) x.begin(),x.end()
map<vector<int>,int> mp;
int n;
mt19937 rng(time(NULL));

int query(vector<int> vec){
    for(auto &v:vec){
        v++;
    }
    int x=Query(vec);
    return x;
}

}  // namespace

void Solve(int N) {
    using namespace std;
    n=N;
    n*=2;
    vector<vector<int>> one(n);
    vector<bool> two(n);
    vector<int> B;
    for(int i=0;i<n;i++){
        B.push_back(i);
    }
    shuffle(all(B),rng);
    while(!B.empty()){
        vector<int> tmp;
        vector<int> A;
        for(auto v:B){
            int prv=(int)A.size();
            A.push_back(v);
            if(query(A)<=prv){
                A.pop_back();
                tmp.push_back(v);
            }
        }
        B=tmp;
        for(auto v:B){
            A.push_back(v);
            vector<int> del;
            while(query(A)!=(int)A.size()){
                A.pop_back();
                int l=0,r=(int)A.size()-1;
                while(l<r){
                    int mid=(l+r)/2;
                    vector<int> cur={v};
                    for(int i=0;i<=mid;i++){
                        cur.push_back(A[i]);
                    }
                    if(query(cur)!=(int)cur.size()){
                        r=mid;
                    }
                    else{
                        l=mid+1;
                    }
                }
                swap(A[l],A[(int)A.size()-1]);
                one[v].push_back(A.back());
                one[A.back()].push_back(v);
                //cout<<v+1<<' '<<A.back()+1<<'\n';
                del.push_back(A.back());
                A.pop_back();
                A.push_back(v);
            }
            A.pop_back();
            for(auto v:del){
                A.push_back(v);
            }
        }
    }
    for(int i=0;i<n;i++){
        if((int)one[i].size()!=1 and (int)one[i].size()!=3){
            cout<<-1<<'\n';
            return;
        }
        if((int)one[i].size()==1){
            two[i]=true;
            continue;
        }
        int a=one[i][0];
        int b=one[i][1];
        int c=one[i][2];
        if(query({i,a,b})==1){
            one[i]={a,b};
        }
        else if(query({i,b,c})==1){
            one[i]={b,c};
        }
        else{
            one[i]={c,a};
        }
    }
    vector<bool> used(n);
    for(int i=0;i<n;i++){
        if(used[i]) continue;
        if(two[i]){
            Answer(i+1,one[i][0]+1);
            used[i]=used[one[i][0]]=true;
            continue;
        }
        int a=one[i][0];
        int b=one[i][1];
        if(two[a]){
            Answer(i+1,a+1);
            used[i]=used[a]=true;
            continue;
        }
        else if(two[b]){
            Answer(i+1,b+1);
            used[i]=used[b]=true;
            continue;
        }
        else{
            if(one[a][0]==i or one[a][1]==i){
                Answer(i+1,a+1);
                used[i]=used[a]=true;
            }
            else{
                Answer(i+1,b+1);
                used[i]=used[b]=true;
            }
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 18 ms 344 KB Output is correct
4 Correct 18 ms 344 KB Output is correct
5 Correct 19 ms 544 KB Output is correct
6 Correct 18 ms 344 KB Output is correct
7 Correct 18 ms 424 KB Output is correct
8 Correct 19 ms 600 KB Output is correct
9 Correct 18 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 47 ms 344 KB Output is correct
4 Correct 47 ms 548 KB Output is correct
5 Correct 47 ms 744 KB Output is correct
6 Correct 47 ms 344 KB Output is correct
7 Correct 47 ms 344 KB Output is correct
8 Correct 46 ms 344 KB Output is correct
9 Correct 47 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 18 ms 344 KB Output is correct
4 Correct 18 ms 344 KB Output is correct
5 Correct 19 ms 544 KB Output is correct
6 Correct 18 ms 344 KB Output is correct
7 Correct 18 ms 424 KB Output is correct
8 Correct 19 ms 600 KB Output is correct
9 Correct 18 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 47 ms 344 KB Output is correct
31 Correct 47 ms 548 KB Output is correct
32 Correct 47 ms 744 KB Output is correct
33 Correct 47 ms 344 KB Output is correct
34 Correct 47 ms 344 KB Output is correct
35 Correct 46 ms 344 KB Output is correct
36 Correct 47 ms 344 KB Output is correct
37 Correct 47 ms 344 KB Output is correct
38 Correct 18 ms 344 KB Output is correct
39 Correct 47 ms 544 KB Output is correct
40 Correct 47 ms 344 KB Output is correct
41 Correct 47 ms 528 KB Output is correct
42 Correct 18 ms 344 KB Output is correct
43 Correct 49 ms 344 KB Output is correct
44 Correct 54 ms 1032 KB Output is correct
45 Correct 48 ms 344 KB Output is correct