답안 #923905

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
923905 2024-02-08T06:06:01 Z alexander707070 카멜레온의 사랑 (JOI20_chameleon) C++14
0 / 100
0 ms 344 KB
#include <bits/stdc++.h>
#include "chameleon.h"
#define MAXN 1007
 
using namespace std;
 
namespace {
 
int n,bad[MAXN],st,lt,rt,mid,li[MAXN],tim;
vector<int> to[MAXN],v[MAXN];
vector< pair<int,int> > sol;
 
vector<int> l,r,w,perm;

void dfs(int x,int side){
    li[x]=tim;
    
    if(side==0)l.push_back(x);
    else r.push_back(x);
    
    for(int i=0;i<v[x].size();i++){
        if(li[v[x][i]]==tim)continue;
        dfs(v[x][i],1-side);
    }
}
 
}  // namespace

 
void Solve(int N) {
 
    n=N;
    for(int i=1;i<=2*n;i++){
            
        for(int f=0;f<3;f++){
            st=lt=rt; rt=l.size()+1;
            while(lt+1<rt){
                mid=(lt+rt)/2;
                
                w.clear();
                for(int i=st;i<mid;i++)w.push_back(l[i]);
                w.push_back(i);
                
                if(Query(w)!=w.size()){
                    rt=mid;
                }else{
                    lt=mid;
                }
            }
            
            if(rt!=l.size()+1){
                v[i].push_back(l[rt-1]);
                v[l[rt-1]].push_back(i);
            }
        }
        
        for(int f=0;f<3;f++){
            st=lt=rt; rt=r.size()+1;
            while(lt+1<rt){
                mid=(lt+rt)/2;
                
                w.clear();
                for(int i=st;i<mid;i++)w.push_back(r[i]);
                w.push_back(i);
                
                if(Query(w)!=w.size()){
                    rt=mid;
                }else{
                    lt=mid;
                }
            }
            
            if(rt!=r.size()+1){
                v[i].push_back(r[rt-1]);
                v[r[rt-1]].push_back(i);
            }
        }
        
        l.clear(); r.clear(); tim++;
        for(int f=1;f<=2*n;f++){
            if(li[f]!=tim)dfs(f,0);
        }
    }
    
    for(int i=1;i<=2*n;i++){
        to[i]=v[i];
    }
        
    for(int i=1;i<=2*n;i++){
        if(to[i].empty())continue;
 
        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}::dfs(int, int)':
chameleon.cpp:21:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:44:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |                 if(Query(w)!=w.size()){
      |                    ~~~~~~~~^~~~~~~~~~
chameleon.cpp:51:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |             if(rt!=l.size()+1){
      |                ~~^~~~~~~~~~~~
chameleon.cpp:66:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |                 if(Query(w)!=w.size()){
      |                    ~~~~~~~~^~~~~~~~~~
chameleon.cpp:73:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |             if(rt!=r.size()+1){
      |                ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Wrong Answer [2]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Wrong Answer [2]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Wrong Answer [2]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Wrong Answer [2]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Wrong Answer [2]
2 Halted 0 ms 0 KB -