답안 #923914

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
923914 2024-02-08T06:22:04 Z alexander707070 카멜레온의 사랑 (JOI20_chameleon) C++14
44 / 100
44 ms 600 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++){
        lt=rt=0;
        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 e=st;e<mid;e++)w.push_back(l[e]);
                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);
            }
        }

        lt=rt=0;
        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 e=st;e<mid;e++)w.push_back(r[e]);
                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<=i;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].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:67:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |                 if(Query(w)!=w.size()){
      |                    ~~~~~~~~^~~~~~~~~~
chameleon.cpp:74:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |             if(rt!=r.size()+1){
      |                ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 40 ms 520 KB Output is correct
4 Correct 43 ms 600 KB Output is correct
5 Correct 36 ms 344 KB Output is correct
6 Correct 37 ms 520 KB Output is correct
7 Correct 37 ms 344 KB Output is correct
8 Correct 37 ms 344 KB Output is correct
9 Correct 36 ms 520 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 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 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 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 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 496 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 368 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 1 ms 344 KB Output is correct
3 Incorrect 44 ms 520 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 Correct 40 ms 520 KB Output is correct
4 Correct 43 ms 600 KB Output is correct
5 Correct 36 ms 344 KB Output is correct
6 Correct 37 ms 520 KB Output is correct
7 Correct 37 ms 344 KB Output is correct
8 Correct 37 ms 344 KB Output is correct
9 Correct 36 ms 520 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 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 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 496 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 368 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 1 ms 344 KB Output is correct
30 Incorrect 44 ms 520 KB Wrong Answer [3]
31 Halted 0 ms 0 KB -