답안 #909551

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
909551 2024-01-17T09:06:54 Z rxlfd314 통행료 (IOI18_highway) C++17
51 / 100
234 ms 262144 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ari2 = array<int, 2>;
 
#define vt vector
#define size(x) (int((x).size()))
#define all(x) begin(x), end(x)
 
#define REP(a, b, c, d) for (int a = (b); (d) > 0 ? a <= (c) : a >= (c); a += (d))
#define FOR(a, b, c) REP(a, b, c, 1)
#define ROF(a, b, c) REP(a, b, c, -1)
 
void find_pair(int N, vt<int> U, vt<int> V, int A, int B) {
  const int M = size(U);
  vt<ari2> adj[N];
  FOR(i, 0, M-1) {
    adj[U[i]].push_back({V[i], i});
    adj[V[i]].push_back({U[i], i});
  }
  ll C = ask(vt<int>(M));
  vt<int> nodes[2];
  function<void(int, int, bool)> dfs = [&](int i, int p, bool c) {
    nodes[c].push_back(i);
    for (auto [j, _] : adj[i])
      if (j != p)
        dfs(j, i, !c);
  };
  dfs(0, 0, 0);
  vt<int> poss;
  if (C / A & 1) {
    poss = nodes[0];
    goto jail;
  }
  FOR(_, 0, 1) {
    FOR(b, 0, 31 - __builtin_clz(size(nodes[_]))) {
      vt<int> v(M);
      FOR(ii, 0, size(nodes[_])-1)
        if (ii & 1 << b) {
          int i = nodes[_][ii];
          poss.push_back(i);
          for (auto [__, j] : adj[i])
            v[j] = 1;
        }
      ll X = ask(v);
      int a = (X - C) / (B - A);
      if (a & 1)
        break;
      poss.clear();
    }
    if (size(poss))
      break;
  }
  jail:;
  #ifdef DEBUG
  cout << "possible:";
  for (int i : poss)
    cout << ' ' << i;
  cout << '\n';
  #endif
  int lo = 0, hi = size(poss) - 1;
  while (lo < hi) {
    int mid = lo + hi >> 1;
    vt<int> v(M);
    FOR(ii, 0, mid) {
      int i = poss[ii];
      for (auto [_, j] : adj[i])
        v[j] = 1;
    }
    ll X = ask(v);
    int a = (X - C) / (B - A);
    if (a & 1)
      hi = mid;
    else
      lo = mid + 1;
  }
  int ep = poss[lo];
  poss.clear();
  int par[N];
  function<void(int, int, int)> dfs2 = [&](int i, int p, int d) {
    if (d == C / A) {
      poss.push_back(i);
      return;
    }
    for (auto [j, ei] : adj[i])
      if (j != p) {
        par[j] = ei;
        dfs2(j, i, d + 1);
      }
  };
  dfs2(ep, ep, 0);
  lo = 0, hi = size(poss) - 1;
  while (lo < hi) {
    int mid = lo + hi >> 1;
    vt<int> v(M);
    FOR(ii, 0, mid) {
      int i = poss[ii];
      v[par[i]] = 1;
    }
    if (ask(v) != C)
      hi = mid;
    else
      lo = mid + 1;
  }
  answer(ep, poss[lo]);
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:64:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   64 |     int mid = lo + hi >> 1;
      |               ~~~^~~~
highway.cpp:95:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   95 |     int mid = lo + hi >> 1;
      |               ~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 440 KB Output is correct
2 Correct 1 ms 440 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 440 KB Output is correct
5 Correct 1 ms 440 KB Output is correct
6 Correct 0 ms 440 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 0 ms 680 KB Output is correct
10 Correct 0 ms 440 KB Output is correct
11 Correct 0 ms 440 KB Output is correct
12 Correct 1 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 9 ms 1500 KB Output is correct
3 Correct 107 ms 9456 KB Output is correct
4 Correct 99 ms 9128 KB Output is correct
5 Correct 109 ms 8732 KB Output is correct
6 Correct 106 ms 9068 KB Output is correct
7 Correct 94 ms 8964 KB Output is correct
8 Correct 83 ms 8984 KB Output is correct
9 Correct 98 ms 9284 KB Output is correct
10 Correct 114 ms 9100 KB Output is correct
11 Correct 73 ms 9520 KB Output is correct
12 Correct 89 ms 10452 KB Output is correct
13 Correct 99 ms 9820 KB Output is correct
14 Correct 102 ms 9396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2036 KB Output is correct
2 Correct 16 ms 3700 KB Output is correct
3 Correct 25 ms 5408 KB Output is correct
4 Correct 117 ms 14864 KB Output is correct
5 Correct 62 ms 15128 KB Output is correct
6 Correct 70 ms 14960 KB Output is correct
7 Correct 69 ms 14960 KB Output is correct
8 Correct 72 ms 15116 KB Output is correct
9 Correct 80 ms 15108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 9 ms 1380 KB Output is correct
3 Correct 60 ms 7216 KB Output is correct
4 Correct 78 ms 9192 KB Output is correct
5 Correct 66 ms 8852 KB Output is correct
6 Correct 120 ms 8952 KB Output is correct
7 Correct 107 ms 9132 KB Output is correct
8 Correct 81 ms 8724 KB Output is correct
9 Correct 135 ms 9052 KB Output is correct
10 Correct 118 ms 9092 KB Output is correct
11 Correct 100 ms 9216 KB Output is correct
12 Correct 127 ms 10764 KB Output is correct
13 Correct 118 ms 9984 KB Output is correct
14 Correct 151 ms 10788 KB Output is correct
15 Correct 85 ms 8672 KB Output is correct
16 Correct 78 ms 8724 KB Output is correct
17 Correct 125 ms 10456 KB Output is correct
18 Correct 116 ms 9772 KB Output is correct
19 Correct 160 ms 9204 KB Output is correct
20 Correct 99 ms 11164 KB Output is correct
21 Correct 104 ms 9492 KB Output is correct
22 Correct 75 ms 10200 KB Output is correct
23 Correct 101 ms 9548 KB Output is correct
24 Correct 119 ms 10168 KB Output is correct
25 Correct 142 ms 14760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 232 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 234 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -