Submission #1032232

# Submission time Handle Problem Language Result Execution time Memory
1032232 2024-07-23T13:43:48 Z NeroZein Chameleon's Love (JOI20_chameleon) C++17
100 / 100
41 ms 600 KB
#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;  

bool bad(vector<int> ask, int v) {
  ask.push_back(v);
  return Query(ask) != (int) ask.size();
}

void Solve(int N) {
  vector<bool> vis(N * 2 + 1);
  vector<vector<int>> g(N * 2 + 1);
  function<void(int, int, vector<vector<int>>&)> dfs = [&](int v, int parity, vector<vector<int>>& p) {
    if (vis[v] == true) {
      return;
    }
    vis[v] = true;
    p[parity].push_back(v);
    for (int u : g[v]) {
      dfs(u, parity ^ 1, p);
    }
  };
  for (int i = 2; i <= 2 * N; ++i) {
    vector<vector<int>> p(2);
    for (int j = 1; j < i; ++j) {
      vis[j] = false; 
    }
    for (int j = 1; j < i; ++j) {
      if (!vis[j]) {
        dfs(j, 0, p);
      }
    }
    for (int rep = 0; rep < 2; ++rep) {
      while (true) {
        if (!bad(p[rep], i)) {
          break; 
        }
        int m = (int) p[rep].size();
        int l = -1, r = m - 1;
        while (l < r) {
          int mid = (l + r + 1) >> 1;
          vector<int> ask;
          for (int j = 0; j <= mid; ++j) {
            ask.push_back(p[rep][j]);
          }
          if (bad(ask, i)) {
            r = mid - 1; 
          } else {
            l = mid;
          }
        }
        if (r == m - 1) {
          break; 
        }
        g[p[rep][l + 1]].push_back(i);
        g[i].push_back(p[rep][l + 1]);
        vector<int> np;
        for (int j = l + 2; j < m; ++j) {
          np.push_back(p[rep][j]);
        }
        swap(p[rep], np); 
      }
    }
  }
  vector<bool> f(2 * N + 1);
  vector<int> love(2 * N + 1);
  for (int v = 1; v <= 2 * N; ++v) {
    if (g[v].size() == 1) {
      if (!f[v]) {
        Answer(v, g[v][0]);        
      }
      f[v] = true;
      f[g[v][0]] = true; 
      continue; 
    }
    assert(g[v].size() == 3);
    int x = g[v][0] ^ g[v][1] ^ g[v][2];
    for (int i = 0; i < 3 && !love[v]; ++i) {
      for (int j = i + 1; j < 3; ++j) {
        int u = g[v][i], w = g[v][j];
        int k = Query({u, v, w});
        if (k == 1) {
          love[v] = x ^ u ^ w;
          break; 
        }
      }
    }
  }
  for (int v = 1; v <= N * 2; ++v) {
    if (f[v]) {
      continue; 
    }
    for (int u : g[v]) {
      if (u != love[v] && love[u] != v) {
        f[u] = true;
        f[v] = true; 
        Answer(u, v);
        break; 
      }
    }
  }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 19 ms 344 KB Output is correct
4 Correct 24 ms 344 KB Output is correct
5 Correct 25 ms 344 KB Output is correct
6 Correct 19 ms 508 KB Output is correct
7 Correct 19 ms 540 KB Output is correct
8 Correct 19 ms 344 KB Output is correct
9 Correct 19 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 444 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 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 444 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 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 39 ms 596 KB Output is correct
4 Correct 39 ms 600 KB Output is correct
5 Correct 39 ms 528 KB Output is correct
6 Correct 40 ms 592 KB Output is correct
7 Correct 39 ms 592 KB Output is correct
8 Correct 41 ms 548 KB Output is correct
9 Correct 38 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 19 ms 344 KB Output is correct
4 Correct 24 ms 344 KB Output is correct
5 Correct 25 ms 344 KB Output is correct
6 Correct 19 ms 508 KB Output is correct
7 Correct 19 ms 540 KB Output is correct
8 Correct 19 ms 344 KB Output is correct
9 Correct 19 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 444 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 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 39 ms 596 KB Output is correct
31 Correct 39 ms 600 KB Output is correct
32 Correct 39 ms 528 KB Output is correct
33 Correct 40 ms 592 KB Output is correct
34 Correct 39 ms 592 KB Output is correct
35 Correct 41 ms 548 KB Output is correct
36 Correct 38 ms 592 KB Output is correct
37 Correct 38 ms 592 KB Output is correct
38 Correct 19 ms 344 KB Output is correct
39 Correct 38 ms 592 KB Output is correct
40 Correct 38 ms 592 KB Output is correct
41 Correct 39 ms 576 KB Output is correct
42 Correct 19 ms 344 KB Output is correct
43 Correct 40 ms 592 KB Output is correct
44 Correct 38 ms 600 KB Output is correct
45 Correct 38 ms 572 KB Output is correct