Submission #600540

# Submission time Handle Problem Language Result Execution time Memory
600540 2022-07-21T04:18:13 Z MilosMilutinovic Highway Tolls (IOI18_highway) C++14
100 / 100
251 ms 11992 KB
#include "highway.h"
#include <bits/stdc++.h>

using namespace std;

void find_pair(int n, vector<int> u, vector<int> v, int a, int b) {
  int m = (int) u.size();
  vector<vector<pair<int, int>>> g(n);
  for (int i = 0; i < m; i++) {
    g[u[i]].emplace_back(v[i], i);
    g[v[i]].emplace_back(u[i], i);
  }
  long long d = ask(vector<int>(m, 0));
  int low = 0, high = m - 1, id = -1;
  while (low <= high) {
    int mid = low + high >> 1;
    vector<int> qv(m);
    for (int i = 0; i <= mid; i++) {
      qv[i] = 1;
    }
    if (ask(qv) != d) {
      id = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  vector<int> ver(2);
  ver[0] = u[id];
  ver[1] = v[id];
  vector<vector<int>> dist(2, vector<int>(n, -1));
  for (int t = 0; t < 2; t++) {
    vector<int> que(1, ver[t]);
    dist[t][ver[t]] = 0;
    for (int b = 0; b < (int) que.size(); b++) {
      int i = que[b];
      for (auto &p : g[i]) {
        int j = p.first;
        if (dist[t][j] == -1) {
          dist[t][j] = dist[t][i] + 1;
          que.push_back(j);
        }
      }
    }
  }
  vector<int> ans(2);
  for (int t = 0; t < 2; t++) {
    vector<int> que(1, ver[t]);
    vector<int> dep(n, -1);
    dep[ver[t]] = 0;
    int cc = 0;
    vector<int> f, edge(m, -1);
    for (int b = 0; b < (int) que.size(); b++) {
      int i = que[b];
      for (auto &p : g[i]) {
        int j = p.first;
        int idx = p.second;
        if (dist[t][j] < dist[1 - t][j]) {
          if (dep[j] == -1) {
            dep[j] = dep[i] + 1;
            que.push_back(j);
            f.push_back(j);
            edge[idx] = cc++;
          } else if (dep[j] == dep[i] + 1) {
            edge[idx] = n;
          }
        } else {
          edge[idx] = (idx == id ? -1 : n);
        }
      }
    }
    reverse(f.begin(), f.end());
    for (int i = 0; i < m; i++) {
      if (edge[i] != -1 && edge[i] != n) {
        edge[i] = cc - edge[i] - 1;
      }
    }
    int low = 0, high = cc - 1, at = -1;
    while (low <= high) {
      int mid = low + high >> 1;
      vector<int> qv(m);
      for (int i = 0; i < m; i++) {
        if (edge[i] == n || (edge[i] != -1 && edge[i] <= mid)) {
          qv[i] = 1;
        }
      }
      if (ask(qv) != d) {
        at = mid;
        high = mid - 1;
      } else {
        low = mid + 1;
      }
    }
    ans[t] = (at == -1 ? ver[t] : f[at]);
  }
  answer(ans[0], ans[1]);
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:16:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   16 |     int mid = low + high >> 1;
      |               ~~~~^~~~~~
highway.cpp:80:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   80 |       int mid = low + high >> 1;
      |                 ~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 308 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 336 KB Output is correct
2 Correct 9 ms 1420 KB Output is correct
3 Correct 139 ms 10180 KB Output is correct
4 Correct 124 ms 10288 KB Output is correct
5 Correct 123 ms 10176 KB Output is correct
6 Correct 107 ms 10248 KB Output is correct
7 Correct 122 ms 10172 KB Output is correct
8 Correct 133 ms 10336 KB Output is correct
9 Correct 101 ms 10196 KB Output is correct
10 Correct 127 ms 10304 KB Output is correct
11 Correct 155 ms 9220 KB Output is correct
12 Correct 178 ms 9476 KB Output is correct
13 Correct 144 ms 9692 KB Output is correct
14 Correct 168 ms 9768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1360 KB Output is correct
2 Correct 19 ms 2296 KB Output is correct
3 Correct 31 ms 3396 KB Output is correct
4 Correct 96 ms 9372 KB Output is correct
5 Correct 94 ms 9216 KB Output is correct
6 Correct 144 ms 9540 KB Output is correct
7 Correct 84 ms 9680 KB Output is correct
8 Correct 130 ms 9284 KB Output is correct
9 Correct 128 ms 9468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 15 ms 1312 KB Output is correct
3 Correct 88 ms 8236 KB Output is correct
4 Correct 157 ms 10212 KB Output is correct
5 Correct 103 ms 10280 KB Output is correct
6 Correct 124 ms 10188 KB Output is correct
7 Correct 109 ms 10248 KB Output is correct
8 Correct 103 ms 10180 KB Output is correct
9 Correct 147 ms 10136 KB Output is correct
10 Correct 157 ms 10336 KB Output is correct
11 Correct 133 ms 9712 KB Output is correct
12 Correct 171 ms 9524 KB Output is correct
13 Correct 136 ms 9488 KB Output is correct
14 Correct 155 ms 9228 KB Output is correct
15 Correct 110 ms 10188 KB Output is correct
16 Correct 125 ms 10184 KB Output is correct
17 Correct 186 ms 9692 KB Output is correct
18 Correct 131 ms 9612 KB Output is correct
19 Correct 106 ms 10196 KB Output is correct
20 Correct 123 ms 9584 KB Output is correct
21 Correct 141 ms 10372 KB Output is correct
22 Correct 91 ms 10316 KB Output is correct
23 Correct 112 ms 9828 KB Output is correct
24 Correct 156 ms 9880 KB Output is correct
25 Correct 132 ms 9656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1280 KB Output is correct
2 Correct 16 ms 1440 KB Output is correct
3 Correct 192 ms 10532 KB Output is correct
4 Correct 216 ms 10652 KB Output is correct
5 Correct 188 ms 11776 KB Output is correct
6 Correct 251 ms 11692 KB Output is correct
7 Correct 196 ms 11648 KB Output is correct
8 Correct 230 ms 11636 KB Output is correct
9 Correct 171 ms 7828 KB Output is correct
10 Correct 182 ms 8088 KB Output is correct
11 Correct 185 ms 8964 KB Output is correct
12 Correct 204 ms 10332 KB Output is correct
13 Correct 234 ms 11176 KB Output is correct
14 Correct 244 ms 11724 KB Output is correct
15 Correct 197 ms 11724 KB Output is correct
16 Correct 222 ms 8808 KB Output is correct
17 Correct 139 ms 10376 KB Output is correct
18 Correct 107 ms 10632 KB Output is correct
19 Correct 100 ms 10492 KB Output is correct
20 Correct 106 ms 10584 KB Output is correct
21 Correct 219 ms 11888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1280 KB Output is correct
2 Correct 16 ms 1496 KB Output is correct
3 Correct 145 ms 10116 KB Output is correct
4 Correct 201 ms 10472 KB Output is correct
5 Correct 150 ms 10668 KB Output is correct
6 Correct 201 ms 11544 KB Output is correct
7 Correct 167 ms 10560 KB Output is correct
8 Correct 138 ms 10652 KB Output is correct
9 Correct 167 ms 10560 KB Output is correct
10 Correct 194 ms 11560 KB Output is correct
11 Correct 190 ms 11476 KB Output is correct
12 Correct 196 ms 11504 KB Output is correct
13 Correct 185 ms 8960 KB Output is correct
14 Correct 180 ms 7988 KB Output is correct
15 Correct 178 ms 8968 KB Output is correct
16 Correct 162 ms 7980 KB Output is correct
17 Correct 153 ms 8968 KB Output is correct
18 Correct 127 ms 8048 KB Output is correct
19 Correct 210 ms 10428 KB Output is correct
20 Correct 183 ms 11428 KB Output is correct
21 Correct 218 ms 11616 KB Output is correct
22 Correct 220 ms 11540 KB Output is correct
23 Correct 250 ms 11560 KB Output is correct
24 Correct 202 ms 11544 KB Output is correct
25 Correct 186 ms 11656 KB Output is correct
26 Correct 202 ms 11684 KB Output is correct
27 Correct 109 ms 10504 KB Output is correct
28 Correct 115 ms 10492 KB Output is correct
29 Correct 139 ms 10716 KB Output is correct
30 Correct 139 ms 10704 KB Output is correct
31 Correct 111 ms 10472 KB Output is correct
32 Correct 135 ms 10396 KB Output is correct
33 Correct 148 ms 10664 KB Output is correct
34 Correct 108 ms 10488 KB Output is correct
35 Correct 110 ms 10456 KB Output is correct
36 Correct 129 ms 10384 KB Output is correct
37 Correct 136 ms 10592 KB Output is correct
38 Correct 142 ms 10612 KB Output is correct
39 Correct 187 ms 11872 KB Output is correct
40 Correct 198 ms 11900 KB Output is correct
41 Correct 160 ms 11992 KB Output is correct
42 Correct 187 ms 11732 KB Output is correct