답안 #135151

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
135151 2019-07-23T17:05:27 Z IOrtroiii 통행료 (IOI18_highway) C++14
100 / 100
353 ms 10988 KB
#include "highway.h"

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

void find_pair(int n, vector<int> u, vector<int> v, int a, int b) {
   int m = 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);
   }
   vector<int> w(m);
   ll dist = ask(w);
   int l = 0, r = m - 1;
   while (l < r) {
      int md = (l + r) >> 1;
      for (int i = 0; i < m; ++i) {
         w[i] = i <= md;
      }
      if (ask(w) != dist) {
         r = md;
      } else {
         l = md + 1;
      }
   }
   int id = l;
   vector<int> tr;
   vector<int> lc;
   vector<int> rc;
   vector<int> color(n);
   queue<int> q;
   color[u[id]] = 1;
   lc.push_back(u[id]);
   q.push(u[id]);
   color[v[id]] = 2;
   q.push(v[id]);
   rc.push_back(v[id]);
   tr.push_back(id);
   while (!q.empty()) {
      int u = q.front(); q.pop();
      for (auto e : g[u]) {
         int v, id;
         tie(v, id) = e;
         if (!color[v]) {
            if (color[u] == 1) {
               color[v] = 1;
               lc.push_back(v);
            } else {
               color[v] = 2;
               rc.push_back(v);
            }
            tr.push_back(id);
            q.push(v);
         }
      }
   }
   assert(tr.size() == n - 1);
   auto get = [&](vector<int> comp) {
      int sz = comp.size();
      int l = 0, r = sz - 1;
      while (l < r) {
         int md = (l + r) >> 1;
         vector<bool> was(n);
         for (int i = md + 1; i < sz; ++i) {
            was[comp[i]] = true;
         }
         for (int i = 0; i < m; ++i) {
            w[i] = was[u[i]] || was[v[i]];
         }
         if (ask(w) != dist) {
            l = md + 1;
         } else {
            r = md;
         }
      }
      return comp[l];
   };

   answer(get(lc), get(rc));
}

// g++ -std=c++14 grader.cpp highway.cpp

Compilation message

In file included from /usr/include/c++/7/cassert:44:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from highway.cpp:3:
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:61:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    assert(tr.size() == n - 1);
           ~~~~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 324 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 2 ms 404 KB Output is correct
4 Correct 2 ms 320 KB Output is correct
5 Correct 2 ms 320 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 248 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 248 KB Output is correct
10 Correct 2 ms 324 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 23 ms 1348 KB Output is correct
3 Correct 197 ms 9160 KB Output is correct
4 Correct 214 ms 9276 KB Output is correct
5 Correct 210 ms 9240 KB Output is correct
6 Correct 172 ms 9164 KB Output is correct
7 Correct 217 ms 9232 KB Output is correct
8 Correct 198 ms 9220 KB Output is correct
9 Correct 200 ms 9240 KB Output is correct
10 Correct 185 ms 9232 KB Output is correct
11 Correct 214 ms 8592 KB Output is correct
12 Correct 216 ms 8564 KB Output is correct
13 Correct 229 ms 8792 KB Output is correct
14 Correct 230 ms 8660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 1224 KB Output is correct
2 Correct 40 ms 2224 KB Output is correct
3 Correct 63 ms 3076 KB Output is correct
4 Correct 175 ms 8456 KB Output is correct
5 Correct 143 ms 8456 KB Output is correct
6 Correct 158 ms 8628 KB Output is correct
7 Correct 141 ms 8748 KB Output is correct
8 Correct 161 ms 8536 KB Output is correct
9 Correct 189 ms 8608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 26 ms 1400 KB Output is correct
3 Correct 147 ms 7300 KB Output is correct
4 Correct 200 ms 9164 KB Output is correct
5 Correct 193 ms 9184 KB Output is correct
6 Correct 204 ms 9136 KB Output is correct
7 Correct 191 ms 9248 KB Output is correct
8 Correct 202 ms 9156 KB Output is correct
9 Correct 222 ms 9152 KB Output is correct
10 Correct 211 ms 9172 KB Output is correct
11 Correct 208 ms 8620 KB Output is correct
12 Correct 238 ms 8584 KB Output is correct
13 Correct 214 ms 8728 KB Output is correct
14 Correct 242 ms 8472 KB Output is correct
15 Correct 192 ms 9172 KB Output is correct
16 Correct 192 ms 9156 KB Output is correct
17 Correct 219 ms 8612 KB Output is correct
18 Correct 210 ms 8676 KB Output is correct
19 Correct 211 ms 9160 KB Output is correct
20 Correct 208 ms 8644 KB Output is correct
21 Correct 168 ms 9824 KB Output is correct
22 Correct 190 ms 9832 KB Output is correct
23 Correct 161 ms 9564 KB Output is correct
24 Correct 201 ms 9472 KB Output is correct
25 Correct 188 ms 8700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 1392 KB Output is correct
2 Correct 20 ms 1444 KB Output is correct
3 Correct 249 ms 9548 KB Output is correct
4 Correct 188 ms 9892 KB Output is correct
5 Correct 318 ms 10836 KB Output is correct
6 Correct 274 ms 10788 KB Output is correct
7 Correct 305 ms 10844 KB Output is correct
8 Correct 220 ms 10884 KB Output is correct
9 Correct 191 ms 7248 KB Output is correct
10 Correct 255 ms 7524 KB Output is correct
11 Correct 235 ms 8356 KB Output is correct
12 Correct 314 ms 9948 KB Output is correct
13 Correct 315 ms 10436 KB Output is correct
14 Correct 327 ms 10840 KB Output is correct
15 Correct 315 ms 10844 KB Output is correct
16 Correct 284 ms 8364 KB Output is correct
17 Correct 198 ms 9556 KB Output is correct
18 Correct 208 ms 9764 KB Output is correct
19 Correct 194 ms 9640 KB Output is correct
20 Correct 221 ms 9712 KB Output is correct
21 Correct 309 ms 10932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 1272 KB Output is correct
2 Correct 19 ms 1436 KB Output is correct
3 Correct 261 ms 9476 KB Output is correct
4 Correct 296 ms 9652 KB Output is correct
5 Correct 263 ms 9940 KB Output is correct
6 Correct 328 ms 10892 KB Output is correct
7 Correct 225 ms 9568 KB Output is correct
8 Correct 248 ms 9716 KB Output is correct
9 Correct 283 ms 9944 KB Output is correct
10 Correct 334 ms 10792 KB Output is correct
11 Correct 330 ms 10908 KB Output is correct
12 Correct 311 ms 10792 KB Output is correct
13 Correct 268 ms 8352 KB Output is correct
14 Correct 253 ms 7536 KB Output is correct
15 Correct 273 ms 8388 KB Output is correct
16 Correct 288 ms 7460 KB Output is correct
17 Correct 260 ms 8332 KB Output is correct
18 Correct 268 ms 7612 KB Output is correct
19 Correct 311 ms 9812 KB Output is correct
20 Correct 322 ms 10384 KB Output is correct
21 Correct 323 ms 10856 KB Output is correct
22 Correct 352 ms 10856 KB Output is correct
23 Correct 343 ms 10856 KB Output is correct
24 Correct 353 ms 10972 KB Output is correct
25 Correct 346 ms 10876 KB Output is correct
26 Correct 323 ms 10896 KB Output is correct
27 Correct 194 ms 9696 KB Output is correct
28 Correct 202 ms 9612 KB Output is correct
29 Correct 208 ms 9964 KB Output is correct
30 Correct 180 ms 9724 KB Output is correct
31 Correct 200 ms 9736 KB Output is correct
32 Correct 212 ms 9572 KB Output is correct
33 Correct 227 ms 9872 KB Output is correct
34 Correct 198 ms 9620 KB Output is correct
35 Correct 196 ms 9644 KB Output is correct
36 Correct 186 ms 9668 KB Output is correct
37 Correct 193 ms 9892 KB Output is correct
38 Correct 188 ms 9716 KB Output is correct
39 Correct 299 ms 10896 KB Output is correct
40 Correct 301 ms 10988 KB Output is correct
41 Correct 298 ms 10936 KB Output is correct
42 Correct 332 ms 10832 KB Output is correct