답안 #923674

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
923674 2024-02-07T14:50:16 Z alexander707070 카멜레온의 사랑 (JOI20_chameleon) C++14
0 / 100
35 ms 504 KB
#include <bits/stdc++.h>
#include "chameleon.h"
#define MAXN 1007
 
using namespace std;
 
namespace {
 
int n,bad[MAXN];
vector<int> to[MAXN];
vector< pair<int,int> > sol;
 
vector<int> l,r,w,perm;
 
void bin(){

    for(int curr:l){
        
        int lt=0,rt=n+1,mid,st=0;
        while(lt+1<rt){
            mid=(lt+rt)/2;
            
            w.clear();
            for(int f=st;f<mid;f++)w.push_back(r[f]);
            w.push_back(curr);
            
            if(Query(w)!=w.size()){
                rt=mid;
            }else{
                lt=mid;
            }
        }
        
        //if(rt!=n+1)to[curr].push_back(r[rt-1]);

        for(int i=0;i<n;i++){
            if(Query({curr,r[i]})==1)to[curr].push_back(r[i]);
        }
        /*
        lt=st=rt; rt=n+1;
        while(lt+1<rt){
            mid=(lt+rt)/2;
            
            w.clear();
            for(int f=st;f<mid;f++)w.push_back(r[f]);
            w.push_back(curr);
            
            if(Query(w)!=w.size()){
                rt=mid;
            }else{
                lt=mid;
            }
        }
        
        if(rt!=n+1)to[curr].push_back(r[rt-1]);
        
        lt=st=rt; rt=n+1;
        while(lt+1<rt){
            mid=(lt+rt)/2;
            
            w.clear();
            for(int f=st;f<mid;f++)w.push_back(r[f]);
            w.push_back(curr);
            
            if(Query(w)!=w.size()){
                rt=mid;
            }else{
                lt=mid;
            }
        }
        
        if(rt!=n+1)to[curr].push_back(r[rt-1]);
        */
    }
    
    for(int curr:r){
        int lt=0,rt=n+1,mid,st=0;

        while(lt+1<rt){
            mid=(lt+rt)/2;
            
            w.clear();
            for(int f=st;f<mid;f++)w.push_back(l[f]);
            w.push_back(curr);
            
            if(Query(w)!=w.size()){
                rt=mid;
            }else{
                lt=mid;
            }
        }
        
        //if(rt!=n+1)to[curr].push_back(l[rt-1]);

        for(int i=0;i<n;i++){
            if(Query({curr,l[i]})==1)to[curr].push_back(l[i]);
        }
        /*
        lt=st=rt; rt=n+1;
        while(lt+1<rt){
            mid=(lt+rt)/2;
            
            w.clear();
            for(int f=st;f<mid;f++)w.push_back(l[f]);
            w.push_back(curr);
            
            if(Query(w)!=w.size()){
                rt=mid;
            }else{
                lt=mid;
            }
        }
        
        if(rt!=n+1)to[curr].push_back(l[rt-1]);
        
        lt=st=rt; rt=n+1;
        while(lt+1<rt){
            mid=(lt+rt)/2;
            
            w.clear();
            for(int f=st;f<mid;f++)w.push_back(l[f]);
            w.push_back(curr);
            
            if(Query(w)!=w.size()){
                rt=mid;
            }else{
                lt=mid;
            }
        }
        
        if(rt!=n+1)to[curr].push_back(l[rt-1]);
        */
    }
}
 
}  // namespace
 
void Solve(int N) {

    n=N;
    for(int i=1;i<=2*n;i++)perm.push_back(i);

    while(true){
        l.clear(); r.clear();
        random_shuffle(perm.begin(),perm.end());

        for(int i:perm){
            l.push_back(i);
            if(Query(l)!=l.size()){
                l.pop_back();
                r.push_back(i);
            }
        }

        if(l.size()==r.size())break;
    }
    
    bin();
    
    for(int i=1;i<=2*n;i++){
        if(to[i].size()==1)continue;
        else{
            if(Query({i,to[i][0],to[i][1]})==1)bad[i]=to[i][2];
            else if(Query({i,to[i][0],to[i][2]})==1)bad[i]=to[i][1];
            else if(Query({i,to[i][2],to[i][1]})==1)bad[i]=to[i][0];
        }
    }
    
    for(int i=1;i<=2*n;i++){
        for(int f:to[i]){
            if(bad[i]==f or bad[f]==i)continue;
            if(i<f)Answer(i,f);
        }
    }
}

/*

4
1 0 1 0 0 1 1 0
4 4 1 2 1 2 3 3
4 3 8 7 6 5 2 1
*/

Compilation message

chameleon.cpp: In function 'void {anonymous}::bin()':
chameleon.cpp:27:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |             if(Query(w)!=w.size()){
      |                ~~~~~~~~^~~~~~~~~~
chameleon.cpp:86:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |             if(Query(w)!=w.size()){
      |                ~~~~~~~~^~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:149:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  149 |             if(Query(l)!=l.size()){
      |                ~~~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 16 ms 504 KB Wrong Answer [3]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Incorrect 0 ms 344 KB Wrong Answer [1]
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Incorrect 0 ms 344 KB Wrong Answer [1]
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Incorrect 35 ms 344 KB Wrong Answer [3]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 16 ms 504 KB Wrong Answer [3]
4 Halted 0 ms 0 KB -