답안 #933802

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
933802 2024-02-26T10:50:31 Z nguyentunglam 카멜레온의 사랑 (JOI20_chameleon) C++17
100 / 100
62 ms 4440 KB
#include "chameleon.h"
#include <vector>
#include<bits/stdc++.h>

using namespace std;

namespace {
const int NN = 1e3 + 10;

bool vis[NN];

vector<int> adj[NN], arr[2];

int love[NN][NN];

void dfs(int u, int g) {
  vis[u] = 1;
  arr[g].push_back(u);
  for(int &v : adj[u]) if (!vis[v]) dfs(v, g ^ 1);
}

void add (int a, int b) {
  adj[a].push_back(b);
  adj[b].push_back(a);
}

void Find (vector<int> x, int i) {
  if (x.empty()) return;
  vector<int> tmp = x;
  tmp.push_back(i);
  if (Query(tmp) == tmp.size()) return;
  if (x.size() == 1) {
    add(x[0], i);
    return;
  }
  int l = 0, r = x.size() - 1, last = -1;
  while (l <= r) {
    int mid = l + r >> 1;
    tmp = {i};
    for(int j = 0; j <= mid; j++) tmp.push_back(x[j]);
    if (Query(tmp) != tmp.size()) {
      last = mid;
      r = mid - 1;
    } else l = mid + 1;
  }
  assert(last >= 0);
  add(x[last], i);
  x.erase(x.begin() + last);
  Find(x, i);
}

void solve(int n) {
//  for(int i = 1; i <= 2 * n; i++) for(int j = i + 1; j <= 2 * n; j++) {
//    if (Query({i, j}) == 1) {
//      adj[i].push_back(j);
//      adj[j].push_back(i);
//    }
//  }

  for(int i = 2; i <= 2 * n; i++) {
    for(int j = 1; j < i; j++) vis[j] = 0;
    for(int j = 1; j < i; j++) if (!vis[j]) {
      if (arr[0].size() < arr[1].size()) dfs(j, 0);
      else dfs(j, 1);
    }
    for(int j = 0; j < 2; j++) if (!arr[j].empty()) {
      Find(arr[j], i);
      arr[j].clear();
    }
  }

  for(int i = 1; i <= 2 * n; i++) {
    assert(adj[i].size() == 1 || adj[i].size() == 3);
    if (adj[i].size() == 1) continue;
    for(int &j : adj[i]) {
      vector<int> tmp;
      tmp.push_back(i);
      for(int &k : adj[i]) if (k != j) tmp.push_back(k);
      if (Query(tmp) == 1) {
        love[i][j] = 1;
      }
    }
  }

  for(int i = 1; i <= 2 * n; i++) {
    for(int &j : adj[i]) if (i < j && love[i][j] + love[j][i] == 0) {
      Answer(i, j);
    }
  }
}
}  // namespace


void Solve(int n) {
  ::solve(n);
}

Compilation message

chameleon.cpp: In function 'void {anonymous}::Find(std::vector<int>, int)':
chameleon.cpp:31:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   if (Query(tmp) == tmp.size()) return;
      |       ~~~~~~~~~~~^~~~~~~~~~~~~
chameleon.cpp:38:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |     int mid = l + r >> 1;
      |               ~~^~~
chameleon.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     if (Query(tmp) != tmp.size()) {
      |         ~~~~~~~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 21 ms 852 KB Output is correct
4 Correct 21 ms 600 KB Output is correct
5 Correct 20 ms 600 KB Output is correct
6 Correct 20 ms 600 KB Output is correct
7 Correct 21 ms 600 KB Output is correct
8 Correct 21 ms 600 KB Output is correct
9 Correct 21 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 504 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 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 1 ms 344 KB Output is correct
3 Correct 0 ms 504 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 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 2544 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 1 ms 2648 KB Output is correct
14 Correct 2 ms 2648 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 50 ms 4180 KB Output is correct
4 Correct 48 ms 4216 KB Output is correct
5 Correct 44 ms 4432 KB Output is correct
6 Correct 46 ms 4432 KB Output is correct
7 Correct 53 ms 4176 KB Output is correct
8 Correct 44 ms 4440 KB Output is correct
9 Correct 62 ms 4220 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 21 ms 852 KB Output is correct
4 Correct 21 ms 600 KB Output is correct
5 Correct 20 ms 600 KB Output is correct
6 Correct 20 ms 600 KB Output is correct
7 Correct 21 ms 600 KB Output is correct
8 Correct 21 ms 600 KB Output is correct
9 Correct 21 ms 600 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 504 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 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 2544 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 2 ms 2648 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 2648 KB Output is correct
26 Correct 1 ms 2648 KB Output is correct
27 Correct 1 ms 2648 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 50 ms 4180 KB Output is correct
31 Correct 48 ms 4216 KB Output is correct
32 Correct 44 ms 4432 KB Output is correct
33 Correct 46 ms 4432 KB Output is correct
34 Correct 53 ms 4176 KB Output is correct
35 Correct 44 ms 4440 KB Output is correct
36 Correct 62 ms 4220 KB Output is correct
37 Correct 57 ms 4252 KB Output is correct
38 Correct 21 ms 600 KB Output is correct
39 Correct 57 ms 4236 KB Output is correct
40 Correct 47 ms 4176 KB Output is correct
41 Correct 47 ms 4176 KB Output is correct
42 Correct 27 ms 600 KB Output is correct
43 Correct 43 ms 4188 KB Output is correct
44 Correct 47 ms 4276 KB Output is correct
45 Correct 49 ms 4232 KB Output is correct