답안 #679289

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
679289 2023-01-08T02:04:17 Z bachhoangxuan 카멜레온의 사랑 (JOI20_chameleon) C++17
100 / 100
84 ms 596 KB
#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn=1005;
vector<int> edge[maxn],lst[2];
bool vis[maxn];
int res[maxn],pos[maxn];
void dfs(int u,int d){
    vis[u]=true;lst[d].push_back(u);
    for(int v:edge[u]){
        if(!vis[v]) dfs(v,d^1);
    }
}
void Solve(int N) {
    for(int i=1;i<=2*N;i++){
        lst[0].clear();lst[1].clear();
        for(int j=1;j<i;j++) vis[j]=false;
        for(int j=1;j<i;j++){
            if(!vis[j]) dfs(j,0);
        }
        //cout << i << endl;
        for(int j=0;j<2;j++){
            //cout << i << ' ' << j << '\n';
            while(true){
                if(lst[j].empty()) break;
                lst[j].push_back(i);
                if(Query(lst[j])==(int)lst[j].size()) break;
                else lst[j].pop_back();
                int l=1,r=(int)lst[j].size();
                while(r>l){
                    int mid=(r+l-1)>>1;
                    vector<int> p;
                    for(int k=0;k<mid;k++) p.push_back(lst[j][k]);
                    p.push_back(i);
                    if(Query(p)!=(int)p.size()) r=mid;
                    else l=mid+1;
                }
                //cout << i << ' ' << j << ' ' << r << '\n';
                edge[lst[j][r-1]].push_back(i);
                edge[i].push_back(lst[j][r-1]);
                lst[j].erase(lst[j].begin()+r-1);
            }
        }
    }
    for(int i=1;i<=2*N;i++){
        if((int)edge[i].size()==1) res[i]=edge[i][0];
        else{
            int a=Query({i,edge[i][0],edge[i][1]});
            int b=Query({i,edge[i][0],edge[i][2]});
            int c=Query({i,edge[i][1],edge[i][2]});
            if(a==1) pos[i]=edge[i][2];
            else if(b==1) pos[i]=edge[i][1];
            else pos[i]=edge[i][0];
        }
    }
    for(int i=1;i<=2*N;i++){
        if((int)edge[i].size()==1) continue;
        for(int v:edge[i]){
            if(v==pos[i]) continue;
            if(pos[v]!=i) res[i]=v;
        }
    }
    for(int i=1;i<=2*N;i++){
        if(i<res[i]) Answer(i,res[i]);
    }
}

Compilation message

chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:50:17: warning: unused variable 'c' [-Wunused-variable]
   50 |             int c=Query({i,edge[i][1],edge[i][2]});
      |                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 28 ms 368 KB Output is correct
4 Correct 32 ms 468 KB Output is correct
5 Correct 30 ms 368 KB Output is correct
6 Correct 30 ms 336 KB Output is correct
7 Correct 29 ms 356 KB Output is correct
8 Correct 30 ms 364 KB Output is correct
9 Correct 32 ms 356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 84 ms 352 KB Output is correct
4 Correct 75 ms 396 KB Output is correct
5 Correct 76 ms 404 KB Output is correct
6 Correct 76 ms 376 KB Output is correct
7 Correct 79 ms 384 KB Output is correct
8 Correct 79 ms 388 KB Output is correct
9 Correct 76 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 28 ms 368 KB Output is correct
4 Correct 32 ms 468 KB Output is correct
5 Correct 30 ms 368 KB Output is correct
6 Correct 30 ms 336 KB Output is correct
7 Correct 29 ms 356 KB Output is correct
8 Correct 30 ms 364 KB Output is correct
9 Correct 32 ms 356 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 0 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 0 ms 336 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 84 ms 352 KB Output is correct
31 Correct 75 ms 396 KB Output is correct
32 Correct 76 ms 404 KB Output is correct
33 Correct 76 ms 376 KB Output is correct
34 Correct 79 ms 384 KB Output is correct
35 Correct 79 ms 388 KB Output is correct
36 Correct 76 ms 348 KB Output is correct
37 Correct 74 ms 392 KB Output is correct
38 Correct 28 ms 336 KB Output is correct
39 Correct 69 ms 396 KB Output is correct
40 Correct 69 ms 408 KB Output is correct
41 Correct 68 ms 364 KB Output is correct
42 Correct 27 ms 368 KB Output is correct
43 Correct 81 ms 596 KB Output is correct
44 Correct 68 ms 368 KB Output is correct
45 Correct 68 ms 396 KB Output is correct