Submission #1081789

# Submission time Handle Problem Language Result Execution time Memory
1081789 2024-08-30T10:51:24 Z erray Highway Tolls (IOI18_highway) C++17
90 / 100
174 ms 10412 KB
#include "highway.h"
#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG 
  #include "/home/ioi/contests/ioi18_d2/debug.h"
#else 
  #define debug(...) void(37)
#endif

template<typename F = function<bool(const int&)>>
int find_first(int l, int r, F good) {
  ++r;
  int bad = r;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (!good(mid)) {
      l = mid + 1;
    } else {
      r = mid;
    }
  }
  return (l == bad ? -1 : l);
}

void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
  int M = 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);
  }
  /*
  for (int j = 0; j < 50; ++j) {
    std::vector<int> w(M);
    for (int i = 0; i < M; ++i) {
      w[i] = 0;
    }
    long long toll = ask(w);
  }
  answer(0, N - 1);
  */
  int64_t small = ask(vector<int>(M, 0));
  int on_path = find_first(0, N - 1, [&](int m) {
    vector<int> w(M, 0);
    for (int i = 0; i <= m; ++i) {
      for (auto id : g[i]) w[id] = 1;
    }
    int64_t g = ask(w);
    return g != small;
  });
  assert(on_path != -1);
  debug(on_path);
  //you can predetermine if it's S or T but ignore it for now 
  vector<int> que;
  vector<bool> vis(N);
  vector<int> par(N, -1);
  vis[on_path] = true;
  que.push_back(on_path);
  vector<int> start_w(M, 1);
  for (int it = 0; it < int(que.size()); ++it) {
    int v = que[it];
    for (auto id : g[v]) {
      int u = v ^ V[id] ^ U[id];
      if (!vis[u]) {
        vis[u] = true;
        start_w[id] = 0;
        par[u] = v;
        vis[u] = true;
        que.push_back(u);
      }
    }
  }
  auto ord = que;
  reverse(ord.begin(), ord.end());
  int S = ord[find_first(0, N - 2, [&](int m) {
    auto w = start_w;
    for (int i = 0; i <= m; ++i) {
      for (auto id : g[ord[i]]) w[id] = 1;
    }
    int64_t g = ask(w);
    return g != small;
  })];
  debug(S);
  vector<bool> rem(N);
  {
    int v = S;
    while (v != -1) {
      rem[v] = true;
      v = par[v];
    }
  }
  {
    vector<int> new_ord;
    for (auto v : ord) {
      if (!rem[v]) {
        new_ord.push_back(v);
      }
    }
    swap(ord, new_ord);
  }
  debug(ord);
  int Q_ind = find_first(0, int(ord.size()) - 1, [&](int m) {
    auto w = start_w;
    for (int i = 0; i <= m; ++i) {
      for (auto id : g[ord[i]]) w[id] = 1;
    }
    int64_t g = ask(w);
    return g != small;
  });
  debug(Q_ind);
  if (Q_ind == -1) {
    answer(S, on_path);
  } else {
    answer(S, ord[Q_ind]);
  }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 10 ms 1368 KB Output is correct
3 Correct 109 ms 9176 KB Output is correct
4 Correct 110 ms 9180 KB Output is correct
5 Correct 114 ms 9176 KB Output is correct
6 Correct 98 ms 9176 KB Output is correct
7 Correct 113 ms 9280 KB Output is correct
8 Correct 115 ms 9236 KB Output is correct
9 Correct 113 ms 9164 KB Output is correct
10 Correct 107 ms 9176 KB Output is correct
11 Correct 101 ms 9052 KB Output is correct
12 Correct 107 ms 9028 KB Output is correct
13 Correct 95 ms 9028 KB Output is correct
14 Correct 92 ms 9028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1420 KB Output is correct
2 Correct 15 ms 2440 KB Output is correct
3 Correct 25 ms 3316 KB Output is correct
4 Correct 72 ms 9000 KB Output is correct
5 Correct 77 ms 9072 KB Output is correct
6 Correct 70 ms 8540 KB Output is correct
7 Correct 74 ms 9088 KB Output is correct
8 Correct 68 ms 8696 KB Output is correct
9 Correct 79 ms 9312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 10 ms 1204 KB Output is correct
3 Correct 84 ms 7296 KB Output is correct
4 Correct 118 ms 9180 KB Output is correct
5 Correct 128 ms 9176 KB Output is correct
6 Correct 119 ms 9180 KB Output is correct
7 Correct 116 ms 9864 KB Output is correct
8 Correct 130 ms 9152 KB Output is correct
9 Correct 115 ms 9176 KB Output is correct
10 Correct 117 ms 9168 KB Output is correct
11 Correct 94 ms 9032 KB Output is correct
12 Correct 94 ms 9012 KB Output is correct
13 Correct 105 ms 9048 KB Output is correct
14 Correct 118 ms 9032 KB Output is correct
15 Correct 116 ms 9176 KB Output is correct
16 Correct 115 ms 9340 KB Output is correct
17 Correct 106 ms 8964 KB Output is correct
18 Correct 112 ms 9032 KB Output is correct
19 Correct 115 ms 9180 KB Output is correct
20 Correct 116 ms 9064 KB Output is correct
21 Correct 78 ms 9392 KB Output is correct
22 Correct 85 ms 9416 KB Output is correct
23 Correct 78 ms 9424 KB Output is correct
24 Correct 89 ms 9632 KB Output is correct
25 Correct 89 ms 8600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1368 KB Output is correct
2 Correct 12 ms 1452 KB Output is correct
3 Correct 133 ms 9408 KB Output is correct
4 Correct 140 ms 9628 KB Output is correct
5 Correct 165 ms 10132 KB Output is correct
6 Correct 163 ms 10168 KB Output is correct
7 Correct 154 ms 10328 KB Output is correct
8 Correct 172 ms 10352 KB Output is correct
9 Correct 109 ms 6480 KB Output is correct
10 Correct 114 ms 6672 KB Output is correct
11 Correct 112 ms 7460 KB Output is correct
12 Correct 157 ms 9048 KB Output is correct
13 Correct 150 ms 9584 KB Output is correct
14 Correct 174 ms 10012 KB Output is correct
15 Correct 155 ms 10000 KB Output is correct
16 Correct 127 ms 7776 KB Output is correct
17 Correct 93 ms 9516 KB Output is correct
18 Correct 118 ms 9572 KB Output is correct
19 Correct 90 ms 9536 KB Output is correct
20 Correct 97 ms 9616 KB Output is correct
21 Correct 143 ms 10104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1224 KB Output is correct
2 Correct 11 ms 1368 KB Output is correct
3 Partially correct 127 ms 9416 KB Output is partially correct
4 Partially correct 133 ms 9516 KB Output is partially correct
5 Correct 134 ms 9636 KB Output is correct
6 Correct 158 ms 10200 KB Output is correct
7 Partially correct 127 ms 9412 KB Output is partially correct
8 Correct 121 ms 9516 KB Output is correct
9 Partially correct 150 ms 9896 KB Output is partially correct
10 Correct 154 ms 10152 KB Output is correct
11 Correct 159 ms 10132 KB Output is correct
12 Partially correct 154 ms 10412 KB Output is partially correct
13 Correct 114 ms 7444 KB Output is correct
14 Correct 110 ms 6684 KB Output is correct
15 Correct 116 ms 7448 KB Output is correct
16 Correct 114 ms 6732 KB Output is correct
17 Correct 119 ms 7452 KB Output is correct
18 Correct 104 ms 6704 KB Output is correct
19 Correct 140 ms 8976 KB Output is correct
20 Correct 146 ms 9496 KB Output is correct
21 Partially correct 153 ms 10108 KB Output is partially correct
22 Partially correct 172 ms 9976 KB Output is partially correct
23 Partially correct 151 ms 10004 KB Output is partially correct
24 Partially correct 140 ms 10000 KB Output is partially correct
25 Correct 150 ms 10020 KB Output is correct
26 Correct 141 ms 9992 KB Output is correct
27 Correct 100 ms 9820 KB Output is correct
28 Partially correct 93 ms 9500 KB Output is partially correct
29 Partially correct 99 ms 9664 KB Output is partially correct
30 Partially correct 114 ms 9580 KB Output is partially correct
31 Partially correct 113 ms 9568 KB Output is partially correct
32 Partially correct 105 ms 9880 KB Output is partially correct
33 Correct 93 ms 9668 KB Output is correct
34 Correct 94 ms 9548 KB Output is correct
35 Partially correct 115 ms 9544 KB Output is partially correct
36 Partially correct 93 ms 9464 KB Output is partially correct
37 Correct 98 ms 9724 KB Output is correct
38 Correct 111 ms 9840 KB Output is correct
39 Partially correct 154 ms 10084 KB Output is partially correct
40 Correct 152 ms 10060 KB Output is correct
41 Correct 134 ms 10080 KB Output is correct
42 Correct 152 ms 10096 KB Output is correct