답안 #1086439

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086439 2024-09-10T16:10:56 Z juicy CEOI16_icc (CEOI16_icc) C++17
100 / 100
97 ms 856 KB
#include "icc.h"
 
#include <bits/stdc++.h>
 
using namespace std;
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

template<class T>
ostream &operator << (ostream &os, vector<T> a) {
  os << "{";
  for (int i = 0; i < a.size(); ++i) {
    os << (i ? ", " : "") << a[i];
  }
  return os << "}";
}

const int N = 105;
 
int pr[N];
vector<int> ver[N];
 
int qry(vector<int> a, vector<int> b) {
  return query(a.size(), b.size(), &a[0], &b[0]);
}
 
int find(int u) {
  return pr[u] == u ? u : pr[u] = find(pr[u]); 
}
 
int find(vector<int> a, vector<int> b) {
  if (a.size() == 1) {
    return a[0];
  }
  int m = a.size() / 2;
  auto lt = vector(a.begin(), a.begin() + m), rt = vector(a.begin() + m, a.end());
  return qry(lt, b) ? find(lt, b) : find(rt, b);
}
 
void run(int n) {
  iota(pr, pr + n, 0);
  for (int i = 0; i < n; ++i) {
    ver[i].push_back(i + 1);
  }
  for (int e = 0; e < n - 1; ++e) {
    vector<int> root;
    for (int i = 0; i < n; ++i) {
      if (pr[i] == i) {
        root.push_back(i);
      }
    }
    int m = root.size();
    int x = 0, k = -1;
    for (int i = 0; 1 << i < m; ++i) {
      vector<int> a, b;
      for (int j = 0; j < m; ++j) {
        auto &v = j >> i & 1 ? a : b;
        v.insert(v.end(), ver[root[j]].begin(), ver[root[j]].end());
      }
      if (qry(a, b)) {
        x ^= 1 << i;
        k = i;
      }
    }
    int y = 0;
    for (int i = 0; 1 << i < m; ++i) {
      if (i == k) {
        continue;
      }
      vector<int> a, b;
      for (int j = 0; j < m; ++j) {
        auto &v = j & (1 << i | 1 << k) ? a : b;
        v.insert(v.end(), ver[root[j]].begin(), ver[root[j]].end());
      }
      if (!qry(a, b)) {
        y ^= 1 << i;
      }
    }
    x ^= y;
    int u = find(ver[root[x]], ver[root[y]]), v = find(ver[root[y]], ver[root[x]]);
    setRoad(u, v);
    --u, --v;
    for (int x : ver[pr[v]]) {
      pr[x - 1] = pr[u];
      ver[pr[u]].push_back(x);
    }
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 600 KB Ok! 117 queries used.
2 Correct 4 ms 604 KB Ok! 116 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 604 KB Ok! 650 queries used.
2 Correct 22 ms 644 KB Ok! 551 queries used.
3 Correct 23 ms 600 KB Ok! 591 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 640 KB Ok! 1573 queries used.
2 Correct 69 ms 624 KB Ok! 1372 queries used.
3 Correct 80 ms 600 KB Ok! 1613 queries used.
4 Correct 72 ms 640 KB Ok! 1497 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 644 KB Ok! 1564 queries used.
2 Correct 73 ms 644 KB Ok! 1543 queries used.
3 Correct 72 ms 600 KB Ok! 1488 queries used.
4 Correct 75 ms 628 KB Ok! 1608 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 604 KB Ok! 1414 queries used.
2 Correct 68 ms 648 KB Ok! 1433 queries used.
3 Correct 97 ms 628 KB Ok! 1424 queries used.
4 Correct 69 ms 652 KB Ok! 1452 queries used.
5 Correct 77 ms 856 KB Ok! 1587 queries used.
6 Correct 74 ms 604 KB Ok! 1575 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 604 KB Ok! 1448 queries used.
2 Correct 68 ms 600 KB Ok! 1420 queries used.