답안 #313929

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
313929 2020-10-17T10:41:58 Z georgerapeanu 카멜레온의 사랑 (JOI20_chameleon) C++14
100 / 100
161 ms 564 KB
#include "chameleon.h"
#include <vector>
#include <cstdio>
#include <cassert>

using namespace std;

vector<int> graph[1005];
vector<int> groups[2];
bool viz[1005];

void dfs(int nod,int lvl){
    
    viz[nod] = 1;
    groups[lvl].push_back(nod);

    for(auto it:graph[nod]){
        if(viz[it]){
            continue;;
        }
        dfs(it,lvl ^ 1);
    }
}

void make_groups(int pas){
    for(int i = 1;i <= pas;i++){
        viz[i] = false;
    }
    groups[0].clear();
    groups[1].clear();
    for(int i = 1;i <= pas;i++){
        if(viz[i] == 0){
            dfs(i,0);
        }
    }
}

int ans[1005];
int lover[1005];

vector<int> reunite(vector<int> a,vector<int> b){
    vector<int> ans;
    for(auto it:a)ans.push_back(it);
    for(auto it:b)ans.push_back(it);
    return ans;
}
vector<int> prefix(vector<int> a,int ind){
    vector<int> ans;
    for(int i = 0;i <= ind;i++){
        ans.push_back(a[i]);
    }
    return ans;
}
vector<int> del(vector<int> a,int val){
    vector<int> ans;
    for(auto it:a){
        if(it == val){
            continue;
        }
        ans.push_back(it);
    }
    return ans;
}

int my_query(const vector<int> &v){
    return Query(v);
}

void Solve(int n) {
    
    for(int i = 1;i <= 2 * n;i++){
        make_groups(i - 1);

        for(int k = 0;k < 2;k++){
            while(my_query(reunite({i},groups[k])) != reunite({i},groups[k]).size()){
                int st = -1,dr = (int)groups[k].size() - 1;

                while(dr - st > 1){
                    int mid = (st + dr) / 2;
                    if(my_query(reunite({i},prefix(groups[k],mid))) == mid + 2){
                        st = mid;
                    }
                    else{
                        dr = mid;
                    }
                }

                graph[i].push_back(groups[k][dr]);
                graph[groups[k][dr]].push_back(i);

                groups[k] = del(groups[k],groups[k][dr]);
            }
        }
    }

    for(int i = 1;i <= 2 * n;i++){
        if(graph[i].size() == 1){
            continue;
        }
        int loves = 0;
        for(loves = 0;loves < (int)graph[i].size();loves++){
            if(graph[i][(loves + 1) % 3] == graph[i][(loves + 2) % 3]){
                loves = (loves + 1) % 3;
                break;
            }
            if(my_query({i,graph[i][(loves + 1) % 3],graph[i][(loves + 2) % 3]}) == 1){
                break;
            }
        }
        lover[i] = graph[i][loves];
    }

    for(int i = 1;i <= 2 * n;i++){
        if(ans[i] == 0){
            for(auto it:graph[i]){
                if(lover[i] == it || lover[it] == i){
                    continue;
                }
                ans[i] = it;
                ans[it] = i;
                Answer(i,it);
                break;
            }
        }
    }
}

Compilation message

chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:75:52: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |             while(my_query(reunite({i},groups[k])) != reunite({i},groups[k]).size()){
      |                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 60 ms 384 KB Output is correct
4 Correct 60 ms 504 KB Output is correct
5 Correct 63 ms 384 KB Output is correct
6 Correct 60 ms 384 KB Output is correct
7 Correct 62 ms 504 KB Output is correct
8 Correct 59 ms 384 KB Output is correct
9 Correct 65 ms 448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 154 ms 512 KB Output is correct
4 Correct 154 ms 384 KB Output is correct
5 Correct 155 ms 384 KB Output is correct
6 Correct 155 ms 564 KB Output is correct
7 Correct 155 ms 384 KB Output is correct
8 Correct 155 ms 384 KB Output is correct
9 Correct 161 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 60 ms 384 KB Output is correct
4 Correct 60 ms 504 KB Output is correct
5 Correct 63 ms 384 KB Output is correct
6 Correct 60 ms 384 KB Output is correct
7 Correct 62 ms 504 KB Output is correct
8 Correct 59 ms 384 KB Output is correct
9 Correct 65 ms 448 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 154 ms 512 KB Output is correct
31 Correct 154 ms 384 KB Output is correct
32 Correct 155 ms 384 KB Output is correct
33 Correct 155 ms 564 KB Output is correct
34 Correct 155 ms 384 KB Output is correct
35 Correct 155 ms 384 KB Output is correct
36 Correct 161 ms 384 KB Output is correct
37 Correct 138 ms 384 KB Output is correct
38 Correct 59 ms 384 KB Output is correct
39 Correct 131 ms 384 KB Output is correct
40 Correct 131 ms 504 KB Output is correct
41 Correct 133 ms 384 KB Output is correct
42 Correct 59 ms 384 KB Output is correct
43 Correct 156 ms 384 KB Output is correct
44 Correct 133 ms 384 KB Output is correct
45 Correct 134 ms 504 KB Output is correct