답안 #909548

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
909548 2024-01-17T09:05:12 Z rxlfd314 통행료 (IOI18_highway) C++17
12 / 100
251 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[0])-1)
        if (ii & 1 << b) {
          int i = nodes[0][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 436 KB Output is correct
2 Correct 1 ms 440 KB Output is correct
3 Correct 1 ms 444 KB Output is correct
4 Correct 1 ms 440 KB Output is correct
5 Correct 1 ms 440 KB Output is correct
6 Correct 1 ms 436 KB Output is correct
7 Correct 0 ms 440 KB Output is correct
8 Correct 1 ms 692 KB Output is correct
9 Correct 0 ms 440 KB Output is correct
10 Correct 1 ms 436 KB Output is correct
11 Correct 1 ms 436 KB Output is correct
12 Correct 1 ms 444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 9 ms 1372 KB Output is correct
3 Correct 95 ms 8952 KB Output is correct
4 Correct 101 ms 8880 KB Output is correct
5 Correct 95 ms 8736 KB Output is correct
6 Correct 126 ms 9080 KB Output is correct
7 Correct 106 ms 9464 KB Output is correct
8 Correct 86 ms 8848 KB Output is correct
9 Correct 107 ms 9184 KB Output is correct
10 Correct 97 ms 9120 KB Output is correct
11 Correct 121 ms 9500 KB Output is correct
12 Correct 75 ms 10516 KB Output is correct
13 Correct 119 ms 10076 KB Output is correct
14 Correct 131 ms 9324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1940 KB Output is correct
2 Correct 16 ms 3700 KB Output is correct
3 Correct 25 ms 5224 KB Output is correct
4 Correct 71 ms 14936 KB Output is correct
5 Correct 107 ms 15124 KB Output is correct
6 Correct 91 ms 14872 KB Output is correct
7 Correct 66 ms 14872 KB Output is correct
8 Correct 70 ms 14864 KB Output is correct
9 Incorrect 97 ms 15332 KB Output is incorrect: {s, t} is wrong.
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 10 ms 1380 KB Output is correct
3 Correct 88 ms 6980 KB Output is correct
4 Correct 114 ms 8864 KB Output is correct
5 Correct 111 ms 8724 KB Output is correct
6 Incorrect 140 ms 9372 KB Output is incorrect: {s, t} is wrong.
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 251 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 231 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -