답안 #421263

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
421263 2021-06-08T23:43:31 Z timmyfeng 통행료 (IOI18_highway) C++17
100 / 100
329 ms 10008 KB
#include <bits/stdc++.h>
using namespace std;
 
#include "highway.h"
 
const int N = 90000;
 
int order[N], where[N], color[N], dist[2][N], ans[2], n;
vector<int> adj[N];
 
void bfs(int s, int *level) {
    fill(level, level + n, -1);
    level[s] = 0;
 
    queue<int> que;
    que.push(s);
 
    while (!que.empty()) {
        int u = que.front();
        que.pop();
        for (auto c : adj[u]) {
            if (level[c] == -1) {
                level[c] = level[u] + 1;
                que.push(c);
            }
        }
    }
}
 
void find_pair(int n, vector<int> u, vector<int> v, int a, int b) {
    ::n = n;
    int m = u.size();
    long long d = ask(vector<int>(m));
 
    for (int i = 0; i < m; ++i) {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }
 
    int low = 0, high = m - 1;
    while (low < high) {
        int mid = (low + high) / 2;
 
        vector<int> traffic(m);
        for (int i = 0; i <= mid; ++i) {
            traffic[i] = true;
        }
 
        if (ask(traffic) > d) {
            high = mid;
        } else {
            low = mid + 1;
        }
    }
 
    int bridge = low;
    bfs(u[bridge], dist[0]);
    bfs(v[bridge], dist[1]);
 
    for (int i = 0; i < n; ++i) {
        if (dist[0][i] < dist[1][i]) {
            color[i] = 0;
        } else {
            color[i] = 1;
        }
    }
 
    for (int k = 0; k < 2; ++k) {
        int nk = 0;
        for (int i = 0; i < n; ++i) {
            if (color[i] == k) {
                order[nk++] = i;
            }
        }
 
        sort(order, order + nk, [&](int a, int b) {
            return dist[k][a] < dist[k][b];
        });
 
        for (int i = 0; i < nk; ++i) {
            where[order[i]] = i;
        }
 
        low = 0, high = nk - 1;
        while (low < high) {
            int mid = (low + high) / 2;
 
            vector<int> traffic(m);
            for (int i = 0; i < m; ++i) {
                if (i == bridge) {
                    traffic[i] = false;
                } else if (color[u[i]] != color[v[i]]) {
                    traffic[i] = true;
                } else if (dist[color[u[i]]][u[i]] == dist[color[v[i]]][v[i]]) {
                    traffic[i] = true;
                } else if (color[u[i]] != k) {
                    traffic[i] = false;
                } else if (max(where[u[i]], where[v[i]]) <= mid) {
                    traffic[i] = false;
                } else {
                    traffic[i] = true;
                }
            }
 
            if (ask(traffic) > d) {
                low = mid + 1;
            } else {
                high = mid;
            }
        }
 
        ans[k] = order[low];
    }
 
    answer(ans[0], ans[1]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2376 KB Output is correct
2 Correct 2 ms 2408 KB Output is correct
3 Correct 2 ms 2376 KB Output is correct
4 Correct 3 ms 2376 KB Output is correct
5 Correct 2 ms 2416 KB Output is correct
6 Correct 2 ms 2376 KB Output is correct
7 Correct 2 ms 2376 KB Output is correct
8 Correct 2 ms 2376 KB Output is correct
9 Correct 2 ms 2376 KB Output is correct
10 Correct 2 ms 2416 KB Output is correct
11 Correct 2 ms 2376 KB Output is correct
12 Correct 2 ms 2376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2376 KB Output is correct
2 Correct 21 ms 3120 KB Output is correct
3 Correct 179 ms 8948 KB Output is correct
4 Correct 183 ms 8964 KB Output is correct
5 Correct 205 ms 8992 KB Output is correct
6 Correct 185 ms 8884 KB Output is correct
7 Correct 215 ms 8900 KB Output is correct
8 Correct 225 ms 8888 KB Output is correct
9 Correct 182 ms 8972 KB Output is correct
10 Correct 165 ms 8892 KB Output is correct
11 Correct 198 ms 8644 KB Output is correct
12 Correct 210 ms 8708 KB Output is correct
13 Correct 225 ms 8808 KB Output is correct
14 Correct 215 ms 8720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 3016 KB Output is correct
2 Correct 26 ms 4040 KB Output is correct
3 Correct 48 ms 4492 KB Output is correct
4 Correct 125 ms 8616 KB Output is correct
5 Correct 106 ms 8628 KB Output is correct
6 Correct 156 ms 8644 KB Output is correct
7 Correct 157 ms 8724 KB Output is correct
8 Correct 136 ms 8720 KB Output is correct
9 Correct 163 ms 8660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2376 KB Output is correct
2 Correct 40 ms 3104 KB Output is correct
3 Correct 126 ms 7580 KB Output is correct
4 Correct 195 ms 8892 KB Output is correct
5 Correct 160 ms 8892 KB Output is correct
6 Correct 188 ms 8948 KB Output is correct
7 Correct 208 ms 8900 KB Output is correct
8 Correct 183 ms 8876 KB Output is correct
9 Correct 232 ms 8952 KB Output is correct
10 Correct 198 ms 8884 KB Output is correct
11 Correct 213 ms 8736 KB Output is correct
12 Correct 216 ms 8696 KB Output is correct
13 Correct 186 ms 8680 KB Output is correct
14 Correct 197 ms 8696 KB Output is correct
15 Correct 187 ms 8900 KB Output is correct
16 Correct 182 ms 8916 KB Output is correct
17 Correct 227 ms 8728 KB Output is correct
18 Correct 216 ms 8732 KB Output is correct
19 Correct 179 ms 8904 KB Output is correct
20 Correct 231 ms 8708 KB Output is correct
21 Correct 139 ms 9328 KB Output is correct
22 Correct 147 ms 9120 KB Output is correct
23 Correct 165 ms 9288 KB Output is correct
24 Correct 228 ms 9188 KB Output is correct
25 Correct 190 ms 8780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 3072 KB Output is correct
2 Correct 21 ms 3096 KB Output is correct
3 Correct 248 ms 9140 KB Output is correct
4 Correct 268 ms 9272 KB Output is correct
5 Correct 296 ms 9892 KB Output is correct
6 Correct 281 ms 9856 KB Output is correct
7 Correct 243 ms 9940 KB Output is correct
8 Correct 257 ms 9864 KB Output is correct
9 Correct 229 ms 7356 KB Output is correct
10 Correct 165 ms 7692 KB Output is correct
11 Correct 175 ms 8088 KB Output is correct
12 Correct 305 ms 9264 KB Output is correct
13 Correct 260 ms 9456 KB Output is correct
14 Correct 320 ms 9724 KB Output is correct
15 Correct 323 ms 9684 KB Output is correct
16 Correct 301 ms 8104 KB Output is correct
17 Correct 172 ms 9196 KB Output is correct
18 Correct 193 ms 9244 KB Output is correct
19 Correct 181 ms 9216 KB Output is correct
20 Correct 199 ms 9468 KB Output is correct
21 Correct 281 ms 9752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 3032 KB Output is correct
2 Correct 20 ms 3084 KB Output is correct
3 Correct 247 ms 9032 KB Output is correct
4 Correct 206 ms 9252 KB Output is correct
5 Correct 266 ms 9332 KB Output is correct
6 Correct 269 ms 9780 KB Output is correct
7 Correct 163 ms 9280 KB Output is correct
8 Correct 239 ms 9236 KB Output is correct
9 Correct 288 ms 9240 KB Output is correct
10 Correct 290 ms 9888 KB Output is correct
11 Correct 326 ms 9800 KB Output is correct
12 Correct 329 ms 9872 KB Output is correct
13 Correct 228 ms 8172 KB Output is correct
14 Correct 160 ms 7544 KB Output is correct
15 Correct 240 ms 8120 KB Output is correct
16 Correct 159 ms 7536 KB Output is correct
17 Correct 187 ms 8136 KB Output is correct
18 Correct 165 ms 7492 KB Output is correct
19 Correct 263 ms 9084 KB Output is correct
20 Correct 328 ms 9440 KB Output is correct
21 Correct 265 ms 9744 KB Output is correct
22 Correct 262 ms 9764 KB Output is correct
23 Correct 270 ms 9648 KB Output is correct
24 Correct 316 ms 9644 KB Output is correct
25 Correct 306 ms 9712 KB Output is correct
26 Correct 267 ms 9680 KB Output is correct
27 Correct 160 ms 9264 KB Output is correct
28 Correct 157 ms 9336 KB Output is correct
29 Correct 189 ms 9388 KB Output is correct
30 Correct 182 ms 9260 KB Output is correct
31 Correct 164 ms 9240 KB Output is correct
32 Correct 189 ms 9216 KB Output is correct
33 Correct 163 ms 9432 KB Output is correct
34 Correct 198 ms 9228 KB Output is correct
35 Correct 198 ms 9308 KB Output is correct
36 Correct 196 ms 9152 KB Output is correct
37 Correct 202 ms 9464 KB Output is correct
38 Correct 157 ms 9288 KB Output is correct
39 Correct 254 ms 10008 KB Output is correct
40 Correct 283 ms 9708 KB Output is correct
41 Correct 215 ms 9792 KB Output is correct
42 Correct 278 ms 9704 KB Output is correct