답안 #216659

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
216659 2020-03-27T18:56:37 Z AlexPop28 카멜레온의 사랑 (JOI20_chameleon) C++14
100 / 100
85 ms 888 KB
#include <bits/stdc++.h>
#include "chameleon.h"
using namespace std;

int Check(const vector<int> &v, int n, int node) {
  vector<int> u(v.begin(), v.begin() + n + 1);
  u.emplace_back(node);
  return Query(u);
}

void Solve(int n) {
  vector<vector<int>> adj(2 * n + 1);
  vector<vector<int>> sides(2);
  vector<int> col(2 * n + 1);
  
  function<void(int, int)> Split = [&](int node, int c) {
    sides[c].emplace_back(node);
    col[node] = c;
    for (int &x : adj[node]) {
      if (col[x] == -1) {
        Split(x, c ^ 1);
      }
    }
  };

  auto AddEdge = [&](int a, int b) {
    adj[a].emplace_back(b);
    adj[b].emplace_back(a);
  };

  for (int i = 1; i <= 2 * n; ++i) {
    sides[0].clear(); sides[1].clear();
    fill(col.begin(), col.end(), -1);
    for (int j = 1; j < i; ++j) {
      if (col[j] == -1) {
        Split(j, 0);
      }
    }

    for (int side = 0; side < 2; ++side) {
      auto v = sides[side];

      while (!v.empty() && Check(v, v.size() - 1, i) <= v.size()) {
        int lo = 0, hi = v.size() - 1, ans = -1;
        while (lo <= hi) {
          int mid = lo + (hi - lo) / 2;
          if (Check(v, mid, i) <= mid + 1) {
            hi = mid - 1;
            ans = mid;
          } else {
            lo = mid + 1;
          }
        }
        
        int x = v[ans];
        AddEdge(i, x);
        v = vector<int>(v.begin() + ans + 1, v.end());
      }
    }
  }

  int cnt_ans = 0;
  vector<set<int>> link(2 * n + 1);
  
  auto AddLink = [&](int x, int y) {
    link[x].emplace(y);
    if (link[y].count(x)) {
      ++cnt_ans;
      Answer(x, y);
    }
  };

  for (int i = 1; i <= 2 * n; ++i) {
    if ((int)adj[i].size() == 1) {
      AddLink(i, adj[i][0]);
      continue;
    }
    
    int x = Query({i, adj[i][0], adj[i][1]});
    int y = Query({i, adj[i][0], adj[i][2]});

    int z = 2;
    if (x == 2 && y == 2) z = 1;

    if (x == 1) {
      AddLink(i, adj[i][0]);
      AddLink(i, adj[i][1]);
    }
    if (y == 1) {
      AddLink(i, adj[i][0]);
      AddLink(i, adj[i][2]);
    }
    if (z == 1) {
      AddLink(i, adj[i][1]);
      AddLink(i, adj[i][2]);
    }
  }
}  

Compilation message

chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:43:54: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       while (!v.empty() && Check(v, v.size() - 1, i) <= v.size()) {
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 40 ms 424 KB Output is correct
4 Correct 39 ms 504 KB Output is correct
5 Correct 40 ms 504 KB Output is correct
6 Correct 40 ms 504 KB Output is correct
7 Correct 40 ms 504 KB Output is correct
8 Correct 39 ms 508 KB Output is correct
9 Correct 40 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 70 ms 608 KB Output is correct
4 Correct 69 ms 608 KB Output is correct
5 Correct 73 ms 888 KB Output is correct
6 Correct 70 ms 632 KB Output is correct
7 Correct 70 ms 632 KB Output is correct
8 Correct 70 ms 632 KB Output is correct
9 Correct 70 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 40 ms 424 KB Output is correct
4 Correct 39 ms 504 KB Output is correct
5 Correct 40 ms 504 KB Output is correct
6 Correct 40 ms 504 KB Output is correct
7 Correct 40 ms 504 KB Output is correct
8 Correct 39 ms 508 KB Output is correct
9 Correct 40 ms 504 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 6 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 70 ms 608 KB Output is correct
31 Correct 69 ms 608 KB Output is correct
32 Correct 73 ms 888 KB Output is correct
33 Correct 70 ms 632 KB Output is correct
34 Correct 70 ms 632 KB Output is correct
35 Correct 70 ms 632 KB Output is correct
36 Correct 70 ms 632 KB Output is correct
37 Correct 71 ms 632 KB Output is correct
38 Correct 39 ms 504 KB Output is correct
39 Correct 76 ms 636 KB Output is correct
40 Correct 73 ms 632 KB Output is correct
41 Correct 71 ms 632 KB Output is correct
42 Correct 39 ms 512 KB Output is correct
43 Correct 70 ms 632 KB Output is correct
44 Correct 72 ms 632 KB Output is correct
45 Correct 85 ms 632 KB Output is correct