Submission #212050

# Submission time Handle Problem Language Result Execution time Memory
212050 2020-03-22T07:17:18 Z extraterrestrial Chameleon's Love (JOI20_chameleon) C++14
100 / 100
91 ms 652 KB
#include "chameleon.h"
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
//#define int ll

mt19937 rnd(239);

void dfs(int v, int cl, vector<vector<int>> &g, vector<int> &color, vector<bool> &used) {
  used[v] = true;
  color[v] = cl;
  for (auto u : g[v]) {
    if (!used[u]) {
      dfs(u, cl ^ 1, g, color, used);
    }
  }
}

void Solve(int n) {
  vector<vector<int>> g(2 * n + 1);
  vector<int> color(2 * n + 1);
  vector<bool> used(2 * n + 1);
  vector<pair<int, int>> interesting;
  for (int i = 2; i <= 2 * n; i++) {
    fill(all(used), false);
    for (int j = 1; j < i; j++) {
      if (!used[j]) {
        dfs(j, 0, g, color, used);
      }
    }
    vector<int> have0, have1;
    for (int j = 1; j < i; j++) {
      if (color[j] == 0) {
        have0.pb(j);
      }
      else {
        have1.pb(j);
      }
    }
    int cur = 0;
    while (cur < SZ(have0)) {
      vector<int> kek;
      for (int j = cur; j < SZ(have0); j++) {
        kek.pb(have0[j]);
      }
      kek.pb(i);
      if (Query(kek) >= SZ(kek)) {
        break;
      }
      int l = cur - 1, r = SZ(have0);
      while (r - l > 1) {
        int mid = (l + r) / 2;
        vector<int> kek;
        for (int j = cur; j <= mid; j++) {
          kek.pb(have0[j]);
        }
        kek.pb(i);
        if (Query(kek) < SZ(kek)) {
          r = mid;
        }
        else {
          l = mid;
        }
      }
      if (r < SZ(have0)) {
        int v = have0[r];
        interesting.pb({v, i});
        g[v].pb(i);
        g[i].pb(v);
        cur = r + 1;
      }
      else {
        break;
      }
    }
    cur = 0;
    while (cur < SZ(have1)) {
      vector<int> kek;
      for (int j = cur; j < SZ(have1); j++) {
        kek.pb(have1[j]);
      }
      kek.pb(i);
      if (Query(kek) >= SZ(kek)) {
        break;
      }
      int l = cur - 1, r = SZ(have1);
      while (r - l > 1) {
        int mid = (l + r) / 2;
        vector<int> kek;
        for (int j = cur; j <= mid; j++) {
          kek.pb(have1[j]);
        }
        kek.pb(i);
        if (Query(kek) < SZ(kek)) {
          r = mid;
        }
        else {
          l = mid;
        }
      }
      if (r < SZ(have1)) {
        int v = have1[r];
        interesting.pb({v, i});
        g[v].pb(i);
        g[i].pb(v);
        cur = r + 1;
      }
      else {
        break;
      } 
    }
  }
  vector<pair<int, int>> rez;
  for (auto it : interesting) {
    vector<int> kek;
    for (int i = 1; i <= 2 * n; i++) {
      if (i != it.F && i != it.S) {
        kek.pb(i);
      }
    }
    if (Query(kek) < n) {
      rez.pb(it);
    }
  }
  for (auto it : rez) {
    Answer(it.F, it.S);
  }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 51 ms 384 KB Output is correct
4 Correct 50 ms 384 KB Output is correct
5 Correct 51 ms 384 KB Output is correct
6 Correct 51 ms 384 KB Output is correct
7 Correct 51 ms 384 KB Output is correct
8 Correct 50 ms 432 KB Output is correct
9 Correct 56 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 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 4 ms 256 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 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 4 ms 256 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 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 6 ms 384 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 86 ms 504 KB Output is correct
4 Correct 88 ms 640 KB Output is correct
5 Correct 85 ms 512 KB Output is correct
6 Correct 89 ms 652 KB Output is correct
7 Correct 88 ms 536 KB Output is correct
8 Correct 86 ms 504 KB Output is correct
9 Correct 86 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 51 ms 384 KB Output is correct
4 Correct 50 ms 384 KB Output is correct
5 Correct 51 ms 384 KB Output is correct
6 Correct 51 ms 384 KB Output is correct
7 Correct 51 ms 384 KB Output is correct
8 Correct 50 ms 432 KB Output is correct
9 Correct 56 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 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 4 ms 256 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 6 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 6 ms 384 KB Output is correct
27 Correct 6 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 86 ms 504 KB Output is correct
31 Correct 88 ms 640 KB Output is correct
32 Correct 85 ms 512 KB Output is correct
33 Correct 89 ms 652 KB Output is correct
34 Correct 88 ms 536 KB Output is correct
35 Correct 86 ms 504 KB Output is correct
36 Correct 86 ms 508 KB Output is correct
37 Correct 90 ms 504 KB Output is correct
38 Correct 50 ms 384 KB Output is correct
39 Correct 89 ms 504 KB Output is correct
40 Correct 91 ms 636 KB Output is correct
41 Correct 89 ms 504 KB Output is correct
42 Correct 51 ms 384 KB Output is correct
43 Correct 85 ms 504 KB Output is correct
44 Correct 88 ms 508 KB Output is correct
45 Correct 90 ms 512 KB Output is correct