답안 #923916

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
923916 2024-02-08T06:24:33 Z alexander707070 카멜레온의 사랑 (JOI20_chameleon) C++14
100 / 100
58 ms 600 KB
#include <bits/stdc++.h>
#include "chameleon.h"
#define MAXN 1007

using namespace std;

namespace {

bool dali;
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; dali=true;

        l.push_back(i);
        if(Query(l)==l.size())dali=false;
        l.pop_back();

        for(int f=0;dali and 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; dali=true;
        r.push_back(i);
        if(Query(r)==r.size())dali=false;
        r.pop_back();

        for(int f=0;dali and 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:22:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         if(Query(l)==l.size())dali=false;
      |            ~~~~~~~~^~~~~~~~~~
chameleon.cpp:51:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |                 if(Query(w)!=w.size()){
      |                    ~~~~~~~~^~~~~~~~~~
chameleon.cpp:58:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |             if(rt!=l.size()+1){
      |                ~~^~~~~~~~~~~~
chameleon.cpp:66:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         if(Query(r)==r.size())dali=false;
      |            ~~~~~~~~^~~~~~~~~~
chameleon.cpp:78:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |                 if(Query(w)!=w.size()){
      |                    ~~~~~~~~^~~~~~~~~~
chameleon.cpp:85:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |             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 21 ms 344 KB Output is correct
4 Correct 20 ms 532 KB Output is correct
5 Correct 21 ms 344 KB Output is correct
6 Correct 21 ms 544 KB Output is correct
7 Correct 21 ms 344 KB Output is correct
8 Correct 21 ms 344 KB Output is correct
9 Correct 21 ms 536 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 1 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 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 1 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 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 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 596 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 35 ms 592 KB Output is correct
4 Correct 37 ms 540 KB Output is correct
5 Correct 35 ms 592 KB Output is correct
6 Correct 35 ms 516 KB Output is correct
7 Correct 34 ms 600 KB Output is correct
8 Correct 36 ms 592 KB Output is correct
9 Correct 37 ms 552 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 21 ms 344 KB Output is correct
4 Correct 20 ms 532 KB Output is correct
5 Correct 21 ms 344 KB Output is correct
6 Correct 21 ms 544 KB Output is correct
7 Correct 21 ms 344 KB Output is correct
8 Correct 21 ms 344 KB Output is correct
9 Correct 21 ms 536 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 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 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 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 596 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 35 ms 592 KB Output is correct
31 Correct 37 ms 540 KB Output is correct
32 Correct 35 ms 592 KB Output is correct
33 Correct 35 ms 516 KB Output is correct
34 Correct 34 ms 600 KB Output is correct
35 Correct 36 ms 592 KB Output is correct
36 Correct 37 ms 552 KB Output is correct
37 Correct 41 ms 600 KB Output is correct
38 Correct 21 ms 344 KB Output is correct
39 Correct 51 ms 552 KB Output is correct
40 Correct 58 ms 592 KB Output is correct
41 Correct 42 ms 592 KB Output is correct
42 Correct 21 ms 540 KB Output is correct
43 Correct 34 ms 544 KB Output is correct
44 Correct 41 ms 568 KB Output is correct
45 Correct 42 ms 564 KB Output is correct