Submission #616792

# Submission time Handle Problem Language Result Execution time Memory
616792 2022-08-01T06:49:06 Z 이동현(#8506) Chameleon's Love (JOI20_chameleon) C++17
40 / 100
25 ms 384 KB
#include "chameleon.h"
#include <bits/stdc++.h>

using namespace std;

namespace {

int variable_example = 1;

}  // namespace

void Solve(int n) {
    vector<vector<int>> way(n * 2 + 1);

    for(int i = 1; i <= n * 2; ++i){
        for(int j = i + 1; j <= n * 2; ++j){
            if(i == j){
                continue;
            }

            int rv = Query({i, j});

            if(rv == 1){
                way[i].push_back(j);
                way[j].push_back(i);
            }
        }
    }

    vector<vector<int>> gr(2);
    vector<int> chk(n * 2 + 1);

    auto dfs = [&](auto&&self, int x, int col)->void{
        chk[x] = 1;
        gr[col].push_back(x);

        for(auto&nxt:way[x]){
            if(chk[nxt]){
                continue;
            }

            self(self, nxt, 1 - col);
        }
    };

    for(int i = 1; i <= n * 2; ++i){
        if(chk[i]){
            continue;
        }

        dfs(dfs, i, 0);
    }

    chk = vector<int>(n * 2 + 1, 0);

    for(int i = 1; i <= n * 2; ++i){
        if(way[i].size() == 1 && !chk[i]){
            chk[i] = chk[way[i][0]] = 1;

            Answer(i, way[i][0]);
        }
    }

    for(int i = 0; i < n; ++i){
        int id = gr[0][i];
        if(chk[id]){
            continue;
        }

        int did = 0;
        for(int j = 0; j < 2; ++j){
            if(chk[way[id][j]]){
                continue;
            }

            vector<int> f = {0, 0};

            for(int x = 0; x < n; ++x){
                if(x == i){
                    continue;
                }

                if(Query({id, way[id][j], gr[0][x]}) == 1){
                    f[0] = 1;
                    break;
                }
            }
            for(int x = 0; x < n; ++x){
                if(gr[1][x] == way[id][j]){
                    continue;
                }

                if(Query({id, way[id][j], gr[1][x]}) == 1){
                    f[1] = 1;
                    break;
                }
            }

            if(f[0] && f[1]){
                did = 1;

                Answer(id, way[id][j]);

                break;
            }
        }
        if(!did){
            Answer(id, way[id][2]);
        }
    }
}
// #include "chameleon.h"
// #include <vector>

// namespace {

// int variable_example = 1;

// }  // namespace

// void Solve(int N) {
//   std::vector<int> p(3);
//   p[0] = 1;
//   p[1] = 2;
//   p[2] = 3;
//   variable_example = Query(p);
//   for (int i = 0; i < N; ++i) {
//     Answer(i * 2 + 1, i * 2 + 2);
//   }
// }

Compilation message

chameleon.cpp:8:5: warning: '{anonymous}::variable_example' defined but not used [-Wunused-variable]
    8 | int variable_example = 1;
      |     ^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Incorrect 19 ms 384 KB Wrong Answer [3]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 3 ms 236 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 4 ms 320 KB Output is correct
14 Correct 4 ms 316 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 4 ms 208 KB Output is correct
18 Correct 2 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Incorrect 25 ms 332 KB Wrong Answer [3]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Incorrect 19 ms 384 KB Wrong Answer [3]
4 Halted 0 ms 0 KB -