Submission #212791

# Submission time Handle Problem Language Result Execution time Memory
212791 2020-03-24T10:06:19 Z WLZ Chameleon's Love (JOI20_chameleon) C++14
100 / 100
75 ms 504 KB
#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
 
namespace {
  vector< vector<int> > g;
  vector<int> found, st;

  int check(vector<int> v, int cur) {
    v.push_back(cur);
    return (Query(v) < (int) v.size());
  }

  void find(vector<int>& v, int cur) {
    while (check(v, cur)) {
      int lo = 0, hi = (int) v.size() - 1;
      while (lo < hi) {
        int mid = (lo + hi) / 2;
        if (check(vector<int>(v.begin(), v.begin() + mid + 1), cur)) {
          hi = mid;
        } else {
          lo = mid + 1;
        }
      }
      found.push_back(v[lo]);
      v = vector<int>(v.begin() + lo + 1, v.end());
    }
  }
}
 
void dfs(int u) {
  for (auto& v : g[u]) {
    if (st[v] == -1) {
      st[v] = !st[u];
      dfs(v);
    }
  }
}

void Solve(int N) {
  g.resize(2 * N + 1);
  st.resize(2 * N + 1);
  st[1] = 0;
  for (int i = 1; i <= 2 * N; i++) {
    found.clear();
    st.assign(2 * N + 1, -1);
    for (int j = 1; j < i; j++) {
      if (st[j] == -1) {
        st[j] = 0;
        dfs(j);
      }
    }
    vector<int> a, b;
    for (int j = 1; j < i; j++) {
      if (st[j] == 0) {
        a.push_back(j);
      } else {
        b.push_back(j);
      }
    }
    find(a, i);
    find(b, i);
    if (found.empty()) {
      st[i] = 0;
    } else {
      for (auto& x : found) {
        st[i] = !st[x];
        g[i].push_back(x);
        g[x].push_back(i);
      }
    }
  }
  vector<int> used(2 * N + 1, 0), in(2 * N + 1, -1), out(2 * N + 1, -1);
  for (int i = 1; i <= 2 * N; i++) {
    if ((int) g[i].size() == 1) {
      continue;
    }
    if (Query({i, g[i][0], g[i][1]}) == 1) {
      out[i] = g[i][2];
      in[g[i][2]] = i;
    } else if (Query({i, g[i][0], g[i][2]}) == 1) {
      out[i] = g[i][1];
      in[g[i][1]] = i;
    } else {
      out[i] = g[i][0];
      in[g[i][0]] = i;
    }
  }
  for (int i = 1; i <= 2 * N; i++) {
    if (used[i]) {
      continue;
    }
    for (auto& x : g[i]) {
      if (x != in[i] && x != out[i]) {
        Answer(i, x);
        used[i] = used[x] = 1;
      }
    }
  }
}
# 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 38 ms 384 KB Output is correct
4 Correct 39 ms 384 KB Output is correct
5 Correct 38 ms 384 KB Output is correct
6 Correct 38 ms 384 KB Output is correct
7 Correct 39 ms 384 KB Output is correct
8 Correct 38 ms 384 KB Output is correct
9 Correct 38 ms 384 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 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 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 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 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 5 ms 384 KB Output is correct
13 Correct 6 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 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 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 62 ms 384 KB Output is correct
4 Correct 62 ms 460 KB Output is correct
5 Correct 75 ms 384 KB Output is correct
6 Correct 64 ms 384 KB Output is correct
7 Correct 62 ms 504 KB Output is correct
8 Correct 61 ms 384 KB Output is correct
9 Correct 60 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 38 ms 384 KB Output is correct
4 Correct 39 ms 384 KB Output is correct
5 Correct 38 ms 384 KB Output is correct
6 Correct 38 ms 384 KB Output is correct
7 Correct 39 ms 384 KB Output is correct
8 Correct 38 ms 384 KB Output is correct
9 Correct 38 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 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 5 ms 384 KB Output is correct
22 Correct 6 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 5 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 62 ms 384 KB Output is correct
31 Correct 62 ms 460 KB Output is correct
32 Correct 75 ms 384 KB Output is correct
33 Correct 64 ms 384 KB Output is correct
34 Correct 62 ms 504 KB Output is correct
35 Correct 61 ms 384 KB Output is correct
36 Correct 60 ms 384 KB Output is correct
37 Correct 63 ms 468 KB Output is correct
38 Correct 42 ms 384 KB Output is correct
39 Correct 61 ms 448 KB Output is correct
40 Correct 62 ms 384 KB Output is correct
41 Correct 71 ms 384 KB Output is correct
42 Correct 39 ms 420 KB Output is correct
43 Correct 61 ms 504 KB Output is correct
44 Correct 62 ms 384 KB Output is correct
45 Correct 61 ms 504 KB Output is correct