Submission #799978

# Submission time Handle Problem Language Result Execution time Memory
799978 2023-08-01T09:04:15 Z 이성호(#10083) Chameleon's Love (JOI20_chameleon) C++17
100 / 100
40 ms 1440 KB
#include "chameleon.h"
#include <vector>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
vector<int> adj[1005];
bool visited[1005];
bool like[1005][1005];
bool found[1005];
void Solve(int N)
{
  for (int i = 2; i <= 2 * N; i++) {
    //1~i-1 사이에 생길 수 있는 변
    vector<int> div[2];
    fill(visited, visited + 1005, false);
    function<void(int, int)> dfs = [&](int v, int id)
    {
      visited[v] = true;
      div[id].push_back(v);
      for (int i:adj[v]) {
        if (!visited[i]) dfs(i, 1 - id);
      }
    };
    int id = 0;
    for (int j = 1; j <= i - 1; j++) {
      if (!visited[j]) {
        dfs(j, id);
        id = !id;
      }
    }
    for (int k = 0; k < 2; k++) {
      while (!div[k].empty()) {
        vector<int> tmp = div[k]; tmp.push_back(i);
        if (Query(tmp) != tmp.size()) {
          vector<int> cand = div[k];
          while (cand.size() > 1) {
            vector<int> mid;
            for (int p = 0; p < (int)cand.size() / 2; p++) mid.push_back(cand[p]);
            mid.push_back(i);
            if (Query(mid) != mid.size()) {
              mid.pop_back();
              cand = mid;
            }
            else {
              mid.clear();
              for (int p = (int)cand.size() / 2; p < (int)cand.size(); p++) mid.push_back(cand[p]);
              cand = mid;
            }
          }
          int res = cand[0];
          adj[res].push_back(i);
          adj[i].push_back(res);
          div[k].erase(remove(div[k].begin(), div[k].end(), res), div[k].end());
        }
        else break;
      }
    }
  }
  for (int i = 1; i <= 2 * N; i++) {
    if (found[i]) continue;
    if (adj[i].size() == 1) {
      Answer(i, adj[i][0]);
      assert(!found[adj[i][0]]);
      found[i] = found[adj[i][0]] = true;
    }
    else {
      assert(adj[i].size() == 3);
      for (int k = 0; k < 3; k++) {
        vector<int> tmp;
        for (int j = 0; j < 3; j++) {
          if (k != j) tmp.push_back(adj[i][j]);
        }
        tmp.push_back(i);
        if (Query(tmp) == 1) {
          like[i][adj[i][k]] = true;
        }
      }
    }
  }
  for (int i = 1; i <= 2 * N; i++) {
    if (found[i]) continue;
    for (int k:adj[i]) {
      if (found[k]) continue;
      if (!like[i][k] && !like[k][i]) {
        Answer(i, k);
        found[i] = found[k] = true;
        break;
      }
    }
  }
}

Compilation message

chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:36:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         if (Query(tmp) != tmp.size()) {
      |             ~~~~~~~~~~~^~~~~~~~~~~~~
chameleon.cpp:42:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |             if (Query(mid) != mid.size()) {
      |                 ~~~~~~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 14 ms 400 KB Output is correct
4 Correct 14 ms 408 KB Output is correct
5 Correct 14 ms 416 KB Output is correct
6 Correct 14 ms 336 KB Output is correct
7 Correct 14 ms 412 KB Output is correct
8 Correct 14 ms 420 KB Output is correct
9 Correct 14 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 0 ms 336 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 0 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 0 ms 336 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 0 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 1 ms 336 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 464 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 35 ms 1420 KB Output is correct
4 Correct 35 ms 1412 KB Output is correct
5 Correct 35 ms 1432 KB Output is correct
6 Correct 35 ms 1360 KB Output is correct
7 Correct 35 ms 1336 KB Output is correct
8 Correct 35 ms 1364 KB Output is correct
9 Correct 35 ms 1360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 14 ms 400 KB Output is correct
4 Correct 14 ms 408 KB Output is correct
5 Correct 14 ms 416 KB Output is correct
6 Correct 14 ms 336 KB Output is correct
7 Correct 14 ms 412 KB Output is correct
8 Correct 14 ms 420 KB Output is correct
9 Correct 14 ms 420 KB Output is correct
10 Correct 0 ms 336 KB Output is correct
11 Correct 0 ms 336 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 0 ms 336 KB Output is correct
14 Correct 0 ms 336 KB Output is correct
15 Correct 0 ms 336 KB Output is correct
16 Correct 0 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 1 ms 336 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 464 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 0 ms 336 KB Output is correct
29 Correct 0 ms 336 KB Output is correct
30 Correct 35 ms 1420 KB Output is correct
31 Correct 35 ms 1412 KB Output is correct
32 Correct 35 ms 1432 KB Output is correct
33 Correct 35 ms 1360 KB Output is correct
34 Correct 35 ms 1336 KB Output is correct
35 Correct 35 ms 1364 KB Output is correct
36 Correct 35 ms 1360 KB Output is correct
37 Correct 40 ms 1440 KB Output is correct
38 Correct 14 ms 404 KB Output is correct
39 Correct 38 ms 1328 KB Output is correct
40 Correct 35 ms 1352 KB Output is correct
41 Correct 36 ms 1352 KB Output is correct
42 Correct 14 ms 336 KB Output is correct
43 Correct 35 ms 1352 KB Output is correct
44 Correct 36 ms 1408 KB Output is correct
45 Correct 35 ms 1380 KB Output is correct