답안 #257756

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
257756 2020-08-04T17:36:21 Z Bruteforceman 카멜레온의 사랑 (JOI20_chameleon) C++14
100 / 100
77 ms 760 KB
#include "bits/stdc++.h"
#include "chameleon.h"
using namespace std;
namespace {
  const int maxn = 5e3 + 10;
  vector <int> g[maxn];
  int col[maxn];

  void addEdge(int i, int j) {
    g[i].push_back(j);
    g[j].push_back(i);
  }
  void dfs(int x) {
    for(int i : g[x]) {
      if(col[i] == -1) {
        col[i] = col[x] ^ 1;
        dfs(i);
      }
    }
  }
  void partition(int V, vector <int> &u, vector <int> &v) {
    for(int i = 1; i <= V; i++) {
      col[i] = -1;
    }
    for(int i = 1; i <= V; i++) {
      if(col[i] == -1) {
        col[i] = 0;
        dfs(i);
      }
    }
    for(int i = 1; i <= V; i++) {
      if(col[i] == 0) u.push_back(i);
      else v.push_back(i);
    }
  }
  bool makeEdge(vector <int> &v, int i) {
    if(v.size() == 0) return false;
    vector <int> u = v;
    u.push_back(i);
    if(Query(u) == u.size()) return false;
    int l = 0, r = v.size() - 1;
    while(l < r) {
      int mid = (l + r) >> 1;
      vector <int> aux = v;
      aux.resize(mid + 1);
      aux.push_back(i);
      if(Query(aux) == aux.size()) l = mid + 1;
      else r = mid;
    }
    addEdge(v[l], i);
    v.erase(v.begin() + l);
    return true;
  }
  bool makeEdges(vector <int> &v, int i) {
    while(makeEdge(v, i));
  }
}  // namespace

void Solve(int N) {
  for(int i = 1; i <= 2 * N; i++) {
    vector <int> u, v;
    partition(i - 1, u, v);
    makeEdges(u, i);
    makeEdges(v, i);
  }
  set <pair <int, int>> s;
  set <int> done;
  for(int i = 1; i <= 2 * N; i++) {
    if(g[i].size() == 1) {
      int p = i, q = g[i].front();
      if(p > q) swap(p, q);
      s.insert(make_pair(p, q));
      done.insert(p);
      done.insert(q);
    }
  }
  map <pair <int, int>, int> cnt;
  for(int i = 1; i <= 2 * N; i++) {
    if(done.count(i) == 0) {
      for(int x = 0; x < 3; x++) {
        for(int y = x + 1; y < 3; y++) {
          int p = g[i][x], q = g[i][y];
          if(Query(vector <int> ({p, q, i})) == 1) {
            int j = p, k = i;
            if(j > k) swap(j, k);
            cnt[make_pair(j, k)] += 1;
            j = q; k = i;
            if(j > k) swap(j, k);
            cnt[make_pair(j, k)] += 1;
          }
        }
      }
    }
  }
  for(auto i : cnt) if(i.second == 2) s.insert(i.first);
  for(auto i : s) {
    Answer(i.first, i.second);
  }
}

Compilation message

chameleon.cpp: In function 'bool {anonymous}::makeEdge(std::vector<int>&, int)':
chameleon.cpp:40:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(Query(u) == u.size()) return false;
        ~~~~~~~~~^~~~~~~~~~~
chameleon.cpp:47:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       if(Query(aux) == aux.size()) l = mid + 1;
          ~~~~~~~~~~~^~~~~~~~~~~~~
chameleon.cpp: In function 'bool {anonymous}::makeEdges(std::vector<int>&, int)':
chameleon.cpp:56:3: warning: no return statement in function returning non-void [-Wreturn-type]
   }
   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 33 ms 512 KB Output is correct
4 Correct 33 ms 512 KB Output is correct
5 Correct 33 ms 512 KB Output is correct
6 Correct 33 ms 512 KB Output is correct
7 Correct 34 ms 512 KB Output is correct
8 Correct 33 ms 512 KB Output is correct
9 Correct 36 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 0 ms 416 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 0 ms 512 KB Output is correct
9 Correct 0 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 0 ms 416 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 0 ms 512 KB Output is correct
9 Correct 0 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 73 ms 632 KB Output is correct
4 Correct 74 ms 632 KB Output is correct
5 Correct 72 ms 572 KB Output is correct
6 Correct 75 ms 632 KB Output is correct
7 Correct 75 ms 684 KB Output is correct
8 Correct 77 ms 632 KB Output is correct
9 Correct 73 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 33 ms 512 KB Output is correct
4 Correct 33 ms 512 KB Output is correct
5 Correct 33 ms 512 KB Output is correct
6 Correct 33 ms 512 KB Output is correct
7 Correct 34 ms 512 KB Output is correct
8 Correct 33 ms 512 KB Output is correct
9 Correct 36 ms 632 KB Output is correct
10 Correct 0 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 0 ms 416 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 0 ms 512 KB Output is correct
18 Correct 0 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
30 Correct 73 ms 632 KB Output is correct
31 Correct 74 ms 632 KB Output is correct
32 Correct 72 ms 572 KB Output is correct
33 Correct 75 ms 632 KB Output is correct
34 Correct 75 ms 684 KB Output is correct
35 Correct 77 ms 632 KB Output is correct
36 Correct 73 ms 632 KB Output is correct
37 Correct 66 ms 632 KB Output is correct
38 Correct 35 ms 512 KB Output is correct
39 Correct 63 ms 632 KB Output is correct
40 Correct 70 ms 632 KB Output is correct
41 Correct 66 ms 632 KB Output is correct
42 Correct 35 ms 512 KB Output is correct
43 Correct 74 ms 760 KB Output is correct
44 Correct 65 ms 632 KB Output is correct
45 Correct 68 ms 632 KB Output is correct