Submission #213592

# Submission time Handle Problem Language Result Execution time Memory
213592 2020-03-26T08:47:58 Z eriksuenderhauf Chameleon's Love (JOI20_chameleon) C++14
100 / 100
89 ms 512 KB
#include "chameleon.h"
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define vi vector<int>
#define trav(x, a) for (const auto& x: a)
#define pb push_back
using namespace std;
const int N = 1005;
vector<int> adj[N], lv[N];

void Solve(int n) {
  for (int i = 1; i <= 2*n; i++) {
    vi c[2], vis(i+1, 0);
    function<void(int,int)> dfs = [&](int u, int f){
      c[f/2].pb(u); vis[u] = 1;
      trav(v, adj[u])
        if (!vis[v])
          dfs(v, f^2);
    };
    for (int j = 1; j < i; j++)
      if (!vis[j])
        dfs(j, 1);
    for (int j = 0; j < 2; j++) {
      vi ask = c[j];
      while (1) {
        ask.pb(i);
        if (Query(ask) == sz(ask))
          break;
        ask.pop_back();
        int lo = 0, hi = sz(ask)-1;
        while (lo <= hi) {
          int mi = (lo+hi) / 2;
          vi tmp;
          for (int k = 0; k <= mi; k++)
            tmp.pb(ask[k]);
          tmp.pb(i);
          if (Query(tmp) != sz(tmp))
            hi = mi - 1;
          else
            lo = mi + 1;
        }
        adj[i].pb(ask[lo]);
        adj[ask[lo]].pb(i);
        vi tmp;
        for (int i = lo+1; i < sz(ask); i++)
          tmp.pb(ask[i]);
        swap(tmp, ask);
      }
    }
  }
  for (int i = 1; i <= 2*n; i++) {
    if (sz(adj[i]) == 1) {
      if (adj[i][0] < i)
        Answer(adj[i][0], i);
      continue;
    }
    trav(x, adj[i]) {
      vector<int> tmp = {i};
      trav(y, adj[i]) {
        if (x != y)
          tmp.pb(y);
      }
      if (Query(tmp) == 1) {
        lv[i].pb(x); // ->
        lv[x].pb(i); // <-
        break;
      }
    }
  }
  for (int i = 1; i <= 2*n; i++) {
    if (sz(adj[i]) == 1)
      continue;
    set<int> tmp(lv[i].begin(), lv[i].end());
    trav(x, adj[i]) {
      if (tmp.count(x))
        continue;
      if (i > x) // !
        Answer(i, x);
    }
  }
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 46 ms 504 KB Output is correct
4 Correct 47 ms 504 KB Output is correct
5 Correct 47 ms 504 KB Output is correct
6 Correct 47 ms 504 KB Output is correct
7 Correct 47 ms 384 KB Output is correct
8 Correct 47 ms 508 KB Output is correct
9 Correct 47 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 512 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 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 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 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 87 ms 504 KB Output is correct
4 Correct 87 ms 504 KB Output is correct
5 Correct 85 ms 504 KB Output is correct
6 Correct 89 ms 504 KB Output is correct
7 Correct 85 ms 512 KB Output is correct
8 Correct 85 ms 504 KB Output is correct
9 Correct 86 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 46 ms 504 KB Output is correct
4 Correct 47 ms 504 KB Output is correct
5 Correct 47 ms 504 KB Output is correct
6 Correct 47 ms 504 KB Output is correct
7 Correct 47 ms 384 KB Output is correct
8 Correct 47 ms 508 KB Output is correct
9 Correct 47 ms 504 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 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 256 KB Output is correct
18 Correct 5 ms 512 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 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 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 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 87 ms 504 KB Output is correct
31 Correct 87 ms 504 KB Output is correct
32 Correct 85 ms 504 KB Output is correct
33 Correct 89 ms 504 KB Output is correct
34 Correct 85 ms 512 KB Output is correct
35 Correct 85 ms 504 KB Output is correct
36 Correct 86 ms 504 KB Output is correct
37 Correct 87 ms 508 KB Output is correct
38 Correct 47 ms 504 KB Output is correct
39 Correct 88 ms 504 KB Output is correct
40 Correct 86 ms 504 KB Output is correct
41 Correct 89 ms 376 KB Output is correct
42 Correct 46 ms 512 KB Output is correct
43 Correct 87 ms 504 KB Output is correct
44 Correct 87 ms 504 KB Output is correct
45 Correct 87 ms 504 KB Output is correct