답안 #276010

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
276010 2020-08-20T09:35:08 Z doowey 통행료 (IOI18_highway) C++14
100 / 100
383 ms 13728 KB
#include <bits/stdc++.h>
#include "highway.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair

int n;
int m;

const int N = 130500;
int dis[2][N];
int par[2][N];

int c;
vector<pii> T[N];

void bfs(int u){
    dis[c][u]=0;
    par[c][u]=-1;
    queue<int> bf;
    bf.push(u);
    int node;
    while(!bf.empty()){
        node = bf.front();
        bf.pop();
        for(auto x : T[node]){
            if(dis[c][x.fi] > dis[c][node] + 1){
                dis[c][x.fi] = dis[c][node] + 1;
                par[c][x.fi] = x.se;
                bf.push(x.fi);
            }
        }
    }
    c ++ ;
}
struct Node{
    int dist;
    int parid;
    int ndx;
    bool operator<(const Node &F) const {
        return dist < F.dist;
    }
};


void find_pair(int _n, vector<int> u, vector<int> v, int a, int b) {
    n = _n;
    m = u.size();
    vector<int> w(m);
    for(int i = 0 ; i < m ; i ++ ){
        w[i] = 0;
        T[u[i]].push_back(mp(v[i], i));
        T[v[i]].push_back(mp(u[i], i));
    }
    ll dist = ask(w);
    int li = 0, ri = m-1;
    int mid;
    while(li < ri){
        mid = (li + ri) / 2;
        for(int j = 0 ; j < m ; j ++ ){
            if(j <= mid)
                w[j] = 0;
            else
                w[j] = 1;
        }
        if(ask(w) == dist)
            ri = mid;
        else
            li = mid + 1;
    }
    int p = u[li];
    int q = v[li];
    int man = li;
    for(int i = 0 ; i < 2; i ++ ){
        for(int j = 0 ; j < n; j ++ ){
            dis[i][j] = (int)1e9;
            par[i][j] = -1;
        }
    }
    bfs(p);
    bfs(q);
    vector<Node> cell[2];
    for(int i = 0 ; i < n; i ++ ){
        if(dis[0][i] == dis[1][i]){
            continue;
        }
        else if(dis[0][i] < dis[1][i]){
            cell[0].push_back({dis[0][i], par[0][i], i});
        }
        else{
            cell[1].push_back({dis[1][i], par[1][i], i});
        }
    }
    sort(cell[0].begin(), cell[0].end());
    sort(cell[1].begin(), cell[1].end());
    li = 0, ri = (int)cell[0].size() - 1;
    while(li < ri){
        mid = (li + ri) / 2;
        for(int i = 0 ; i < m ; i ++ ){
            w[i] = 1;
        }
        w[man] = 0;
        for(auto f : cell[1]){
            if(f.parid != -1){
                w[f.parid] = 0;
            }
        }
        for(int i = 0 ; i <= mid; i ++ ){
            if(cell[0][i].parid != -1)
                w[cell[0][i].parid] = 0;
        }
        if(ask(w) == dist)
            ri = mid;
        else
            li = mid + 1;
    }
    int S,T;
    S = cell[0][li].ndx;
    li = 0, ri = (int)cell[1].size() - 1;
    while(li < ri){
        mid = (li + ri) / 2;
        for(int i = 0 ; i < m; i ++ ){
            w[i] = 1;
        }
        w[man] = 0;
        for(auto f : cell[0]){
            if(f.parid != -1){
                w[f.parid] = 0;
            }
        }
        for(int i = 0 ; i <= mid; i ++ ){
            if(cell[1][i].parid != -1){
                w[cell[1][i].parid] = 0;
            }
        }
        if(ask(w) == dist)
            ri = mid;
        else
            li = mid + 1;
    }
    T = cell[1][li].ndx;
    answer(S,T);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Correct 3 ms 3456 KB Output is correct
3 Correct 3 ms 3456 KB Output is correct
4 Correct 2 ms 3456 KB Output is correct
5 Correct 2 ms 3456 KB Output is correct
6 Correct 2 ms 3456 KB Output is correct
7 Correct 2 ms 3452 KB Output is correct
8 Correct 3 ms 3456 KB Output is correct
9 Correct 2 ms 3456 KB Output is correct
10 Correct 3 ms 3452 KB Output is correct
11 Correct 3 ms 3456 KB Output is correct
12 Correct 2 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Correct 18 ms 4480 KB Output is correct
3 Correct 163 ms 11656 KB Output is correct
4 Correct 155 ms 11624 KB Output is correct
5 Correct 166 ms 11676 KB Output is correct
6 Correct 157 ms 11760 KB Output is correct
7 Correct 157 ms 11676 KB Output is correct
8 Correct 206 ms 11720 KB Output is correct
9 Correct 186 ms 12048 KB Output is correct
10 Correct 158 ms 11608 KB Output is correct
11 Correct 179 ms 10712 KB Output is correct
12 Correct 299 ms 11540 KB Output is correct
13 Correct 188 ms 11120 KB Output is correct
14 Correct 234 ms 11120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 4352 KB Output is correct
2 Correct 27 ms 5188 KB Output is correct
3 Correct 45 ms 6068 KB Output is correct
4 Correct 174 ms 11172 KB Output is correct
5 Correct 139 ms 10940 KB Output is correct
6 Correct 130 ms 11104 KB Output is correct
7 Correct 212 ms 11104 KB Output is correct
8 Correct 125 ms 10908 KB Output is correct
9 Correct 197 ms 11108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3504 KB Output is correct
2 Correct 19 ms 4480 KB Output is correct
3 Correct 136 ms 10204 KB Output is correct
4 Correct 156 ms 11756 KB Output is correct
5 Correct 271 ms 11728 KB Output is correct
6 Correct 146 ms 11648 KB Output is correct
7 Correct 243 ms 11652 KB Output is correct
8 Correct 242 ms 11708 KB Output is correct
9 Correct 246 ms 11268 KB Output is correct
10 Correct 166 ms 11648 KB Output is correct
11 Correct 179 ms 11032 KB Output is correct
12 Correct 170 ms 11284 KB Output is correct
13 Correct 182 ms 11016 KB Output is correct
14 Correct 168 ms 10948 KB Output is correct
15 Correct 279 ms 11608 KB Output is correct
16 Correct 180 ms 11668 KB Output is correct
17 Correct 177 ms 11240 KB Output is correct
18 Correct 268 ms 11124 KB Output is correct
19 Correct 167 ms 11620 KB Output is correct
20 Correct 175 ms 11128 KB Output is correct
21 Correct 161 ms 12444 KB Output is correct
22 Correct 149 ms 12584 KB Output is correct
23 Correct 226 ms 11836 KB Output is correct
24 Correct 142 ms 11864 KB Output is correct
25 Correct 294 ms 11188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 4344 KB Output is correct
2 Correct 21 ms 4504 KB Output is correct
3 Correct 183 ms 11420 KB Output is correct
4 Correct 200 ms 12376 KB Output is correct
5 Correct 282 ms 12984 KB Output is correct
6 Correct 322 ms 13352 KB Output is correct
7 Correct 231 ms 12992 KB Output is correct
8 Correct 249 ms 13020 KB Output is correct
9 Correct 296 ms 9936 KB Output is correct
10 Correct 174 ms 10356 KB Output is correct
11 Correct 175 ms 11160 KB Output is correct
12 Correct 219 ms 12052 KB Output is correct
13 Correct 246 ms 12512 KB Output is correct
14 Correct 244 ms 13056 KB Output is correct
15 Correct 266 ms 12956 KB Output is correct
16 Correct 215 ms 10996 KB Output is correct
17 Correct 258 ms 11904 KB Output is correct
18 Correct 249 ms 12128 KB Output is correct
19 Correct 134 ms 12056 KB Output is correct
20 Correct 206 ms 12044 KB Output is correct
21 Correct 233 ms 13572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 4320 KB Output is correct
2 Correct 19 ms 4472 KB Output is correct
3 Correct 161 ms 11996 KB Output is correct
4 Correct 197 ms 11936 KB Output is correct
5 Correct 275 ms 12544 KB Output is correct
6 Correct 290 ms 13356 KB Output is correct
7 Correct 200 ms 11732 KB Output is correct
8 Correct 269 ms 11812 KB Output is correct
9 Correct 207 ms 12372 KB Output is correct
10 Correct 383 ms 12904 KB Output is correct
11 Correct 248 ms 13072 KB Output is correct
12 Correct 228 ms 13516 KB Output is correct
13 Correct 177 ms 11104 KB Output is correct
14 Correct 325 ms 10304 KB Output is correct
15 Correct 179 ms 11120 KB Output is correct
16 Correct 169 ms 10236 KB Output is correct
17 Correct 177 ms 11224 KB Output is correct
18 Correct 192 ms 10324 KB Output is correct
19 Correct 211 ms 12168 KB Output is correct
20 Correct 216 ms 12820 KB Output is correct
21 Correct 367 ms 12804 KB Output is correct
22 Correct 232 ms 12876 KB Output is correct
23 Correct 271 ms 12928 KB Output is correct
24 Correct 233 ms 13412 KB Output is correct
25 Correct 249 ms 13148 KB Output is correct
26 Correct 276 ms 13136 KB Output is correct
27 Correct 143 ms 12016 KB Output is correct
28 Correct 219 ms 11956 KB Output is correct
29 Correct 222 ms 12304 KB Output is correct
30 Correct 267 ms 11960 KB Output is correct
31 Correct 258 ms 12064 KB Output is correct
32 Correct 146 ms 11816 KB Output is correct
33 Correct 253 ms 12120 KB Output is correct
34 Correct 150 ms 11916 KB Output is correct
35 Correct 133 ms 12052 KB Output is correct
36 Correct 145 ms 11880 KB Output is correct
37 Correct 153 ms 12216 KB Output is correct
38 Correct 159 ms 11960 KB Output is correct
39 Correct 246 ms 13728 KB Output is correct
40 Correct 235 ms 13696 KB Output is correct
41 Correct 273 ms 13604 KB Output is correct
42 Correct 241 ms 13128 KB Output is correct