답안 #441480

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441480 2021-07-05T08:56:02 Z prvocislo 통행료 (IOI18_highway) C++17
100 / 100
361 ms 15060 KB
#include "highway.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const int maxn = 9e4 + 5, maxm = 1.3e5 + 5;
vector<pair<int, int> > g[maxn]; // {index hrany, kam ide}
vector<int> t[maxn]; // hrany v bfs strome ale opacne
vector<int> mn[2]; // mnozina v ktorej moze byt s, mnozina v ktorej moze byt t
void find_pair(int n, vector<int> U, vector<int> V, int A, int B) {
  int m = U.size();
  vector<int> w(m, 0);
  ll wa = ask(w);
  int lo = 0, hi = m-1;
  while (lo < hi)
  {
    int mi = (lo+hi)>>1;
    for (int i = 0; i < m; i++) w[i] = (i <= mi);
    if (ask(w) == wa) lo = mi+1; // Prvych mi hran nema ziaden vplyv na odpoved, id bude nejaka vyssia hrana.
    else hi = mi; 
  }
  int id = lo;
  for (int i = id; i < m; i++) g[U[i]].push_back({i, V[i]}), g[V[i]].push_back({i, U[i]});
  queue<int> q;
  vector<int> d(maxn, -1), x(maxn, 0);
  d[U[id]] = d[V[id]] = 0, x[U[id]] = 1, x[V[id]] = 2;
  q.push(U[id]), q.push(V[id]);
  while (!q.empty())
  {
    int u = q.front(); q.pop();
    if (x[u]&1) mn[0].push_back(u);
    if (x[u]&2) mn[1].push_back(u);
    for (pair<int, int> i : g[u])
    {
      if (d[i.second] == -1) d[i.second] = d[u] + 1, x[i.second] = x[u], q.push(i.second);
      if (d[i.second] == d[u] + 1) t[i.second].push_back(i.first);
    }
  }
  vector<int> ans(2, -1);
  for (int it = 0; it < 2; it++)
  {
    int lo = 0, hi = mn[it].size() - 1;
    while (lo < hi)
    {
      int mi = (lo+hi+1)>>1;
      w.assign(m, 0);
      for (int i = 0; i < id; i++) w[i] = 1;
      for (int i = mi; i < mn[it].size(); i++)
      {
        if (mn[it][i] == ans[0]) continue;
        for (int j : t[mn[it][i]]) w[j] = 1;
      }
      if (ask(w) == wa) hi = mi-1; // tieto vrcholy neovplivnili dlzku najkratsej cesty, treba ist nizsie
      else lo = mi;
    }
    ans[it] = mn[it][lo];
  }
  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:48:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |       for (int i = mi; i < mn[it].size(); i++)
      |                        ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5192 KB Output is correct
2 Correct 3 ms 5192 KB Output is correct
3 Correct 3 ms 5192 KB Output is correct
4 Correct 3 ms 5192 KB Output is correct
5 Correct 3 ms 5160 KB Output is correct
6 Correct 3 ms 5192 KB Output is correct
7 Correct 3 ms 5164 KB Output is correct
8 Correct 4 ms 5192 KB Output is correct
9 Correct 3 ms 5192 KB Output is correct
10 Correct 4 ms 5192 KB Output is correct
11 Correct 3 ms 5192 KB Output is correct
12 Correct 3 ms 5192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5320 KB Output is correct
2 Correct 18 ms 6124 KB Output is correct
3 Correct 185 ms 12876 KB Output is correct
4 Correct 170 ms 12900 KB Output is correct
5 Correct 207 ms 13676 KB Output is correct
6 Correct 124 ms 11868 KB Output is correct
7 Correct 163 ms 11532 KB Output is correct
8 Correct 217 ms 13532 KB Output is correct
9 Correct 188 ms 11656 KB Output is correct
10 Correct 195 ms 12608 KB Output is correct
11 Correct 165 ms 10168 KB Output is correct
12 Correct 189 ms 12796 KB Output is correct
13 Correct 184 ms 12868 KB Output is correct
14 Correct 211 ms 12984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 5960 KB Output is correct
2 Correct 38 ms 6700 KB Output is correct
3 Correct 35 ms 6052 KB Output is correct
4 Correct 104 ms 10736 KB Output is correct
5 Correct 112 ms 10756 KB Output is correct
6 Correct 150 ms 11772 KB Output is correct
7 Correct 135 ms 7320 KB Output is correct
8 Correct 105 ms 11204 KB Output is correct
9 Correct 141 ms 8528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5192 KB Output is correct
2 Correct 22 ms 5952 KB Output is correct
3 Correct 130 ms 11820 KB Output is correct
4 Correct 194 ms 12808 KB Output is correct
5 Correct 143 ms 9876 KB Output is correct
6 Correct 111 ms 10188 KB Output is correct
7 Correct 190 ms 11528 KB Output is correct
8 Correct 108 ms 10276 KB Output is correct
9 Correct 159 ms 13100 KB Output is correct
10 Correct 186 ms 12144 KB Output is correct
11 Correct 222 ms 12860 KB Output is correct
12 Correct 188 ms 12680 KB Output is correct
13 Correct 167 ms 12032 KB Output is correct
14 Correct 119 ms 10496 KB Output is correct
15 Correct 134 ms 10284 KB Output is correct
16 Correct 99 ms 9148 KB Output is correct
17 Correct 213 ms 12660 KB Output is correct
18 Correct 177 ms 12992 KB Output is correct
19 Correct 102 ms 9804 KB Output is correct
20 Correct 154 ms 9856 KB Output is correct
21 Correct 134 ms 11484 KB Output is correct
22 Correct 155 ms 9032 KB Output is correct
23 Correct 188 ms 14116 KB Output is correct
24 Correct 206 ms 14132 KB Output is correct
25 Correct 163 ms 13088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 6120 KB Output is correct
2 Correct 26 ms 6112 KB Output is correct
3 Correct 231 ms 13796 KB Output is correct
4 Correct 223 ms 13196 KB Output is correct
5 Correct 287 ms 13652 KB Output is correct
6 Correct 360 ms 15056 KB Output is correct
7 Correct 317 ms 14296 KB Output is correct
8 Correct 268 ms 13856 KB Output is correct
9 Correct 136 ms 7804 KB Output is correct
10 Correct 150 ms 10020 KB Output is correct
11 Correct 178 ms 10908 KB Output is correct
12 Correct 305 ms 14072 KB Output is correct
13 Correct 324 ms 14652 KB Output is correct
14 Correct 325 ms 14676 KB Output is correct
15 Correct 320 ms 14864 KB Output is correct
16 Correct 257 ms 12340 KB Output is correct
17 Correct 166 ms 13004 KB Output is correct
18 Correct 157 ms 10124 KB Output is correct
19 Correct 138 ms 13652 KB Output is correct
20 Correct 163 ms 11620 KB Output is correct
21 Correct 288 ms 14984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 6124 KB Output is correct
2 Correct 22 ms 6272 KB Output is correct
3 Correct 264 ms 13876 KB Output is correct
4 Correct 280 ms 13692 KB Output is correct
5 Correct 268 ms 13752 KB Output is correct
6 Correct 276 ms 14404 KB Output is correct
7 Correct 181 ms 13936 KB Output is correct
8 Correct 256 ms 14052 KB Output is correct
9 Correct 268 ms 13584 KB Output is correct
10 Correct 312 ms 14436 KB Output is correct
11 Correct 307 ms 14928 KB Output is correct
12 Correct 298 ms 14552 KB Output is correct
13 Correct 199 ms 7812 KB Output is correct
14 Correct 180 ms 7828 KB Output is correct
15 Correct 253 ms 12484 KB Output is correct
16 Correct 165 ms 10012 KB Output is correct
17 Correct 236 ms 10816 KB Output is correct
18 Correct 180 ms 10148 KB Output is correct
19 Correct 276 ms 13760 KB Output is correct
20 Correct 340 ms 14572 KB Output is correct
21 Correct 321 ms 14684 KB Output is correct
22 Correct 288 ms 14500 KB Output is correct
23 Correct 281 ms 14840 KB Output is correct
24 Correct 361 ms 14812 KB Output is correct
25 Correct 254 ms 14336 KB Output is correct
26 Correct 329 ms 14856 KB Output is correct
27 Correct 148 ms 11524 KB Output is correct
28 Correct 231 ms 13312 KB Output is correct
29 Correct 230 ms 14688 KB Output is correct
30 Correct 183 ms 14044 KB Output is correct
31 Correct 166 ms 13556 KB Output is correct
32 Correct 163 ms 13640 KB Output is correct
33 Correct 168 ms 14508 KB Output is correct
34 Correct 164 ms 12284 KB Output is correct
35 Correct 135 ms 12952 KB Output is correct
36 Correct 204 ms 13824 KB Output is correct
37 Correct 205 ms 13324 KB Output is correct
38 Correct 160 ms 13668 KB Output is correct
39 Correct 339 ms 15036 KB Output is correct
40 Correct 318 ms 15060 KB Output is correct
41 Correct 220 ms 14996 KB Output is correct
42 Correct 330 ms 14960 KB Output is correct