답안 #1010721

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1010721 2024-06-29T09:59:49 Z salmon 카멜레온의 사랑 (JOI20_chameleon) C++14
100 / 100
85 ms 652 KB
#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;

int lst[1100];
bool vis[1100];
vector<int> blonk;
set<int> v[2];
vector<int> adjlst[1100];
int connect[1100];

void ffs(int i, int p){
    v[1 - p].erase(i);
    v[p].insert(i);
    vis[i] = true;
    lst[i] = p;

    for(int j : adjlst[i]){
        if(!vis[j]) ffs(j,1-p);
    }
}

int fid(vector<int> v, int i){
    if(v.size() == 1) return v[0];

    vector<int> temp = {i};

    int m = (v.size() - 1)/2;

    for(int i = 0; i <= m; i++){
        temp.push_back(v[i]);
    }

    if(temp.size() != Query(temp)){
        temp.clear();
        for(int i = 0; i <= m; i++){
            temp.push_back(v[i]);
        }
        return fid(temp,i);
    }
    else{
        temp.clear();
        for(int i = m + 1; i < v.size(); i++){
            temp.push_back(v[i]);
        }
        return fid(temp,i);
    }
}

void Solve(int N) {
    for(int i = 1; i <= N * 2; i++){
        lst[i] = -1;
    }

    for(int i = 1; i <= N * 2; i++){
        vector<int> temp(v[1].begin(),v[1].end());
        vector<int> ext;
        vector<int> con;

        temp.push_back(i);
        while(temp.size() != Query(temp)){
            for(int j = 1; j <= N * 2; j++){
                vis[j] = false;
            }
            temp.pop_back();
            int num = fid(temp,i);
            temp.push_back(i);

            ext.clear();

            for(int i : temp){
                if(i == num) continue;
                ext.push_back(i);
            }
            temp = ext;

            con.push_back(num);
        }

        temp.clear();
        for(int i : v[0]){
            temp.push_back(i);
        }

        temp.push_back(i);
        while(temp.size() != Query(temp)){
            for(int j = 1; j <= N * 2; j++){
                vis[j] = false;
            }
            temp.pop_back();
            int num = fid(temp,i);
            temp.push_back(i);

            ext.clear();

            for(int i : temp){
                if(i == num) continue;
                ext.push_back(i);
            }
            temp = ext;

            con.push_back(num);
        }

        for(int j : con){
            adjlst[i].push_back(j);
            adjlst[j].push_back(i);
        }

        for(int j = 1; j <= N * 2; j++){
            vis[j] = false;
        }
        ffs(i,0);
    }

    for(int i = 1; i <= N * 2; i++) connect[i] = -1;

    for(int i = 1; i <= N * 2; i++){
        if(adjlst[i].size() == 3){
            int h1 = Query({i,adjlst[i][0],adjlst[i][1]});
            int h2 = Query({i,adjlst[i][0],adjlst[i][2]});
            int h3 = Query({i,adjlst[i][1],adjlst[i][2]});

            if(h1 == h2){
                connect[i] = adjlst[i][0];
            }
            else if(h1 == h3){
                connect[i] = adjlst[i][1];
            }
            else{
                connect[i] = adjlst[i][2];
            }
        }
    }

    for(int i : v[0]){
        if(adjlst[i].size() == 1){
            Answer(i,adjlst[i][0]);
        }
        else{
            for(int j : adjlst[i]){
                if(connect[i] == j) continue;
                if(connect[j] == i) continue;
                Answer(i,j);
            }
        }
    }
}

Compilation message

chameleon.cpp: In function 'int fid(std::vector<int>, int)':
chameleon.cpp:34:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |     if(temp.size() != Query(temp)){
      |        ~~~~~~~~~~~~^~~~~~~~~~~~~~
chameleon.cpp:43:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for(int i = m + 1; i < v.size(); i++){
      |                            ~~^~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:61:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   61 |         while(temp.size() != Query(temp)){
      |               ~~~~~~~~~~~~^~~~~~~~~~~~~~
chameleon.cpp:86:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   86 |         while(temp.size() != Query(temp)){
      |               ~~~~~~~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 14 ms 544 KB Output is correct
4 Correct 12 ms 600 KB Output is correct
5 Correct 12 ms 600 KB Output is correct
6 Correct 12 ms 604 KB Output is correct
7 Correct 12 ms 608 KB Output is correct
8 Correct 13 ms 600 KB Output is correct
9 Correct 13 ms 556 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 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 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 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 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 2 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 51 ms 616 KB Output is correct
4 Correct 50 ms 604 KB Output is correct
5 Correct 41 ms 568 KB Output is correct
6 Correct 46 ms 632 KB Output is correct
7 Correct 44 ms 628 KB Output is correct
8 Correct 45 ms 652 KB Output is correct
9 Correct 51 ms 628 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 14 ms 544 KB Output is correct
4 Correct 12 ms 600 KB Output is correct
5 Correct 12 ms 600 KB Output is correct
6 Correct 12 ms 604 KB Output is correct
7 Correct 12 ms 608 KB Output is correct
8 Correct 13 ms 600 KB Output is correct
9 Correct 13 ms 556 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 0 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 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 2 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 51 ms 616 KB Output is correct
31 Correct 50 ms 604 KB Output is correct
32 Correct 41 ms 568 KB Output is correct
33 Correct 46 ms 632 KB Output is correct
34 Correct 44 ms 628 KB Output is correct
35 Correct 45 ms 652 KB Output is correct
36 Correct 51 ms 628 KB Output is correct
37 Correct 68 ms 568 KB Output is correct
38 Correct 13 ms 600 KB Output is correct
39 Correct 72 ms 588 KB Output is correct
40 Correct 65 ms 636 KB Output is correct
41 Correct 66 ms 600 KB Output is correct
42 Correct 14 ms 600 KB Output is correct
43 Correct 54 ms 600 KB Output is correct
44 Correct 85 ms 588 KB Output is correct
45 Correct 74 ms 592 KB Output is correct