Submission #823355

# Submission time Handle Problem Language Result Execution time Memory
823355 2023-08-12T11:18:37 Z KoD Highway Tolls (IOI18_highway) C++17
90 / 100
302 ms 9052 KB
#include "highway.h"

#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <utility>

using std::array;
using std::pair;
using std::string;
using std::tuple;
using std::vector;

using std::begin;
using std::end;

using ll = long long;
constexpr int inf = 1 << 30;
constexpr ll infll = (1ll << 62) - 1;

template <class F> int binary_search(int ok, int ng, const F& f) {
  while (std::abs(ok - ng) > 1) {
    const int md = (ok + ng) / 2;
    (f(md) ? ok : ng) = md;
  }
  return ok;
}

void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
  const int M = (int)U.size();
  vector<vector<int>> G(N);
  for (int i = 0; i < M; ++i) {
    G[U[i]].push_back(i);
    G[V[i]].push_back(i);
  }
  const auto bfs_order = [&](int src) {
    vector<int> ret;
    vector<char> done(N);
    std::queue<int> que;
    ret.reserve(N);
    const auto push = [&](int u) {
      if (!done[u]) {
        done[u] = true;
        ret.push_back(u);
        que.push(u);
      }
    };
    push(src);
    while (!que.empty()) {
      const int u = que.front();
      que.pop();
      for (const int e : G[u]) {
        push(u ^ U[e] ^ V[e]);
      }
    }
    return ret;
  };
  const ll best = ask(vector(M, 0));
  const int P = binary_search(0, N, [&](int thres) -> bool {
    vector<int> w(M);
    for (int i = 0; i < thres; ++i) {
      for (const int e : G[i]) w[e] = 1;
    }
    return ask(w) == best;
  });
  const auto ordP = bfs_order(P);
  const int S = ordP[binary_search(N, 0, [&](int thres) -> bool {
    vector<int> w(M);
    for (int i = thres; i < N; ++i) {
      for (const int e : G[ordP[i]]) w[e] = 1;
    }
    return ask(w) == best;
  }) - 1];
  const auto ordS = bfs_order(S);
  const int T = ordS[binary_search(N, 0, [&](int thres) -> bool {
    vector<int> w(M);
    for (int i = thres; i < N; ++i) {
      for (const int e : G[ordS[i]]) w[e] = 1;
    }
    return ask(w) == best;
  }) - 1];
  answer(S, T);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 380 KB Output is correct
2 Correct 11 ms 1148 KB Output is correct
3 Correct 115 ms 7920 KB Output is correct
4 Correct 108 ms 7932 KB Output is correct
5 Correct 117 ms 7936 KB Output is correct
6 Correct 98 ms 7916 KB Output is correct
7 Correct 112 ms 7932 KB Output is correct
8 Correct 122 ms 8032 KB Output is correct
9 Correct 107 ms 7936 KB Output is correct
10 Correct 108 ms 7928 KB Output is correct
11 Correct 104 ms 7816 KB Output is correct
12 Correct 105 ms 7784 KB Output is correct
13 Correct 142 ms 7792 KB Output is correct
14 Correct 113 ms 7792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1052 KB Output is correct
2 Correct 15 ms 1952 KB Output is correct
3 Correct 45 ms 2896 KB Output is correct
4 Correct 67 ms 7788 KB Output is correct
5 Correct 83 ms 7800 KB Output is correct
6 Correct 63 ms 7768 KB Output is correct
7 Correct 67 ms 7800 KB Output is correct
8 Correct 64 ms 7784 KB Output is correct
9 Correct 69 ms 7796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 448 KB Output is correct
2 Correct 12 ms 1184 KB Output is correct
3 Correct 82 ms 6348 KB Output is correct
4 Correct 137 ms 7932 KB Output is correct
5 Correct 154 ms 7932 KB Output is correct
6 Correct 153 ms 7924 KB Output is correct
7 Correct 135 ms 8080 KB Output is correct
8 Correct 115 ms 7920 KB Output is correct
9 Correct 106 ms 7952 KB Output is correct
10 Correct 130 ms 7936 KB Output is correct
11 Correct 128 ms 7812 KB Output is correct
12 Correct 96 ms 7784 KB Output is correct
13 Correct 137 ms 7780 KB Output is correct
14 Correct 114 ms 7788 KB Output is correct
15 Correct 114 ms 7940 KB Output is correct
16 Correct 130 ms 7936 KB Output is correct
17 Correct 135 ms 7960 KB Output is correct
18 Correct 118 ms 7796 KB Output is correct
19 Correct 131 ms 7944 KB Output is correct
20 Correct 115 ms 7780 KB Output is correct
21 Correct 76 ms 8160 KB Output is correct
22 Correct 81 ms 8272 KB Output is correct
23 Correct 85 ms 8328 KB Output is correct
24 Correct 72 ms 8272 KB Output is correct
25 Correct 106 ms 7948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1104 KB Output is correct
2 Correct 12 ms 1192 KB Output is correct
3 Correct 148 ms 8192 KB Output is correct
4 Correct 133 ms 8428 KB Output is correct
5 Correct 177 ms 9024 KB Output is correct
6 Correct 188 ms 8944 KB Output is correct
7 Correct 181 ms 9052 KB Output is correct
8 Correct 141 ms 8936 KB Output is correct
9 Correct 105 ms 5472 KB Output is correct
10 Correct 124 ms 5716 KB Output is correct
11 Correct 99 ms 6308 KB Output is correct
12 Correct 163 ms 7984 KB Output is correct
13 Correct 143 ms 8444 KB Output is correct
14 Correct 141 ms 8804 KB Output is correct
15 Correct 158 ms 8808 KB Output is correct
16 Correct 127 ms 6552 KB Output is correct
17 Correct 95 ms 8256 KB Output is correct
18 Correct 113 ms 8312 KB Output is correct
19 Correct 84 ms 8260 KB Output is correct
20 Correct 99 ms 8360 KB Output is correct
21 Correct 180 ms 8804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1104 KB Output is correct
2 Correct 10 ms 1148 KB Output is correct
3 Partially correct 141 ms 8216 KB Output is partially correct
4 Partially correct 139 ms 8300 KB Output is partially correct
5 Correct 146 ms 8428 KB Output is correct
6 Partially correct 151 ms 8968 KB Output is partially correct
7 Partially correct 146 ms 8204 KB Output is partially correct
8 Correct 140 ms 8304 KB Output is correct
9 Partially correct 174 ms 8428 KB Output is partially correct
10 Partially correct 180 ms 9012 KB Output is partially correct
11 Partially correct 146 ms 8960 KB Output is partially correct
12 Partially correct 232 ms 8956 KB Output is partially correct
13 Correct 121 ms 6240 KB Output is correct
14 Correct 106 ms 5712 KB Output is correct
15 Correct 114 ms 6152 KB Output is correct
16 Correct 106 ms 5760 KB Output is correct
17 Correct 101 ms 6132 KB Output is correct
18 Correct 132 ms 5856 KB Output is correct
19 Correct 179 ms 7940 KB Output is correct
20 Correct 214 ms 8360 KB Output is correct
21 Partially correct 201 ms 8800 KB Output is partially correct
22 Partially correct 180 ms 8780 KB Output is partially correct
23 Correct 156 ms 8820 KB Output is correct
24 Partially correct 191 ms 8808 KB Output is partially correct
25 Partially correct 217 ms 8788 KB Output is partially correct
26 Correct 179 ms 8868 KB Output is correct
27 Correct 114 ms 8316 KB Output is correct
28 Partially correct 94 ms 8240 KB Output is partially correct
29 Partially correct 101 ms 8396 KB Output is partially correct
30 Partially correct 119 ms 8300 KB Output is partially correct
31 Partially correct 90 ms 8288 KB Output is partially correct
32 Correct 117 ms 8224 KB Output is correct
33 Correct 119 ms 8392 KB Output is correct
34 Correct 102 ms 8284 KB Output is correct
35 Partially correct 126 ms 8292 KB Output is partially correct
36 Correct 126 ms 8216 KB Output is correct
37 Correct 159 ms 8360 KB Output is correct
38 Correct 129 ms 8336 KB Output is correct
39 Correct 302 ms 8800 KB Output is correct
40 Correct 217 ms 8796 KB Output is correct
41 Partially correct 139 ms 8808 KB Output is partially correct
42 Correct 199 ms 8916 KB Output is correct