답안 #933899

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
933899 2024-02-26T14:35:45 Z kim 통행료 (IOI18_highway) C++17
90 / 100
238 ms 12240 KB
#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
#define eb emplace_back
using ll=long long;
using pii=pair<int,int>;
#define f first
#define s second

int n,m;
pii edge[130005];
vector<pii> graph[90005];
vector<int> tmp,ans;
ll mn_ask,dist;
bitset<90005> vis;
int tour[90005];

void solve1(int U){
    int id=0;
    queue<int> q;
    q.emplace(U);
    vis=0;
    vis[U]=1;
    tour[U]=0;
    while(q.size()){
        int u=q.front(); q.pop();
        for(auto &[v,i]:graph[u]){
            if(vis[v]) continue;
            vis[v]=1;
            q.emplace(v);
            tour[v]=++id;
        }
    }
    int l=0,r=id;
    while(l<r){
        int mid=l+r>>1;
        for(int i=0;i<m;++i){
            auto &[u,v]=edge[i];
            if(tour[u]<=mid&&tour[v]<=mid) tmp[i]=0;
            else tmp[i]=1;
        }
        if(ask(tmp)==mn_ask) r=mid;
        else l=mid+1;
    }
    for(int i=0;i<n;++i){
        if(tour[i]==l){
            ans.eb(i);
            return;
        }
    }
}

void solve2(int U){
    queue<pii> q;
    q.emplace(U,0);
    vis=0;
    vis[U]=1;
    vector<int> tmp2(tmp.size(),1);
    vector<pii> vec;
    while(q.size()){
        auto [u,d]=q.front(); q.pop();
        for(auto &[v,id]:graph[u]){
            if(vis[v]) continue;
            if(d+1<dist) q.emplace(v,d+1), tmp2[id]=0;
            else if(d+1==dist) vec.eb(v,id);
            vis[v]=1;
        }
    }
    int l=0,r=vec.size();
    while(l<r){
        int mid=l+r>>1;
        tmp=tmp2;
        for(int i=0;i<=mid;++i) tmp[vec[i].s]=0;
        if(ask(tmp)==mn_ask) r=mid;
        else l=mid+1;
    }
    ans.eb(vec[l].f);
}

void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
    n=N,m=U.size();
    for(int i=0;i<m;++i){
        edge[i]={U[i],V[i]};
        graph[U[i]].eb(V[i],i);
        graph[V[i]].eb(U[i],i);
    }
    tmp.assign(m,0);
    mn_ask=ask(tmp), dist=mn_ask/A;
    solve1(0);
    solve1(ans[0]);
    solve1(ans[1]);
    answer(ans[1],ans[2]);
}
/*
15 15  99 100  9 10
0 1
1 3
3 5
5 7
7 9
9 11
11 13
13 14
14 12
12 10
10 8
8 6
6 4
4 2
2 0
*/

Compilation message

highway.cpp: In function 'void solve1(int)':
highway.cpp:36:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |         int mid=l+r>>1;
      |                 ~^~
highway.cpp: In function 'void solve2(int)':
highway.cpp:71:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   71 |         int mid=l+r>>1;
      |                 ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2752 KB Output is correct
2 Correct 1 ms 2756 KB Output is correct
3 Correct 1 ms 2756 KB Output is correct
4 Correct 1 ms 2756 KB Output is correct
5 Correct 1 ms 2752 KB Output is correct
6 Correct 1 ms 2756 KB Output is correct
7 Correct 1 ms 2752 KB Output is correct
8 Correct 1 ms 2760 KB Output is correct
9 Correct 1 ms 2752 KB Output is correct
10 Correct 1 ms 2752 KB Output is correct
11 Correct 1 ms 2752 KB Output is correct
12 Correct 1 ms 2752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2816 KB Output is correct
2 Correct 10 ms 3596 KB Output is correct
3 Correct 126 ms 10200 KB Output is correct
4 Correct 116 ms 9768 KB Output is correct
5 Correct 129 ms 9772 KB Output is correct
6 Correct 110 ms 9036 KB Output is correct
7 Correct 118 ms 9044 KB Output is correct
8 Correct 168 ms 9300 KB Output is correct
9 Correct 102 ms 9280 KB Output is correct
10 Correct 118 ms 9524 KB Output is correct
11 Correct 122 ms 8856 KB Output is correct
12 Correct 138 ms 8928 KB Output is correct
13 Correct 125 ms 9368 KB Output is correct
14 Correct 171 ms 8668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 3336 KB Output is correct
2 Correct 14 ms 4008 KB Output is correct
3 Correct 25 ms 4632 KB Output is correct
4 Correct 105 ms 8204 KB Output is correct
5 Correct 69 ms 8444 KB Output is correct
6 Correct 90 ms 8704 KB Output is correct
7 Correct 66 ms 8216 KB Output is correct
8 Correct 72 ms 8452 KB Output is correct
9 Correct 80 ms 8676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2824 KB Output is correct
2 Correct 16 ms 3592 KB Output is correct
3 Correct 88 ms 8016 KB Output is correct
4 Correct 109 ms 9484 KB Output is correct
5 Correct 93 ms 9036 KB Output is correct
6 Correct 129 ms 9272 KB Output is correct
7 Correct 104 ms 9512 KB Output is correct
8 Correct 101 ms 9244 KB Output is correct
9 Correct 131 ms 9512 KB Output is correct
10 Correct 135 ms 9748 KB Output is correct
11 Correct 126 ms 8440 KB Output is correct
12 Correct 118 ms 8452 KB Output is correct
13 Correct 118 ms 8924 KB Output is correct
14 Correct 119 ms 8460 KB Output is correct
15 Correct 134 ms 9044 KB Output is correct
16 Correct 97 ms 8804 KB Output is correct
17 Correct 116 ms 8924 KB Output is correct
18 Correct 162 ms 9160 KB Output is correct
19 Correct 97 ms 9516 KB Output is correct
20 Correct 119 ms 8684 KB Output is correct
21 Correct 102 ms 9780 KB Output is correct
22 Correct 139 ms 9540 KB Output is correct
23 Correct 144 ms 10292 KB Output is correct
24 Correct 102 ms 9260 KB Output is correct
25 Correct 142 ms 8516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 3436 KB Output is correct
2 Correct 19 ms 3560 KB Output is correct
3 Correct 143 ms 10184 KB Output is correct
4 Correct 139 ms 10260 KB Output is correct
5 Correct 200 ms 11800 KB Output is correct
6 Correct 180 ms 11800 KB Output is correct
7 Correct 217 ms 12032 KB Output is correct
8 Correct 163 ms 11592 KB Output is correct
9 Correct 150 ms 10092 KB Output is correct
10 Correct 155 ms 10792 KB Output is correct
11 Correct 155 ms 10492 KB Output is correct
12 Correct 173 ms 11140 KB Output is correct
13 Correct 167 ms 11704 KB Output is correct
14 Correct 194 ms 11792 KB Output is correct
15 Correct 197 ms 11360 KB Output is correct
16 Correct 162 ms 10540 KB Output is correct
17 Correct 112 ms 9820 KB Output is correct
18 Correct 118 ms 10224 KB Output is correct
19 Correct 120 ms 10156 KB Output is correct
20 Correct 114 ms 9960 KB Output is correct
21 Correct 156 ms 11356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 3516 KB Output is correct
2 Correct 12 ms 3556 KB Output is correct
3 Correct 154 ms 10232 KB Output is correct
4 Correct 148 ms 9992 KB Output is correct
5 Partially correct 162 ms 10456 KB Output is partially correct
6 Correct 218 ms 11568 KB Output is correct
7 Partially correct 123 ms 9772 KB Output is partially correct
8 Correct 132 ms 10652 KB Output is correct
9 Correct 160 ms 10724 KB Output is correct
10 Partially correct 197 ms 12240 KB Output is partially correct
11 Partially correct 180 ms 11796 KB Output is partially correct
12 Partially correct 201 ms 11812 KB Output is partially correct
13 Correct 161 ms 10632 KB Output is correct
14 Correct 153 ms 10372 KB Output is correct
15 Correct 129 ms 10700 KB Output is correct
16 Correct 183 ms 10548 KB Output is correct
17 Correct 158 ms 10712 KB Output is correct
18 Correct 205 ms 10420 KB Output is correct
19 Correct 238 ms 11592 KB Output is correct
20 Correct 163 ms 11284 KB Output is correct
21 Partially correct 192 ms 11592 KB Output is partially correct
22 Correct 187 ms 11360 KB Output is correct
23 Partially correct 158 ms 11560 KB Output is partially correct
24 Correct 166 ms 11816 KB Output is correct
25 Correct 177 ms 11356 KB Output is correct
26 Partially correct 183 ms 11600 KB Output is partially correct
27 Correct 130 ms 10172 KB Output is correct
28 Partially correct 116 ms 10088 KB Output is partially correct
29 Partially correct 164 ms 10336 KB Output is partially correct
30 Correct 111 ms 10064 KB Output is correct
31 Correct 147 ms 9912 KB Output is correct
32 Partially correct 105 ms 10304 KB Output is partially correct
33 Correct 136 ms 10520 KB Output is correct
34 Partially correct 129 ms 9448 KB Output is partially correct
35 Partially correct 135 ms 9868 KB Output is partially correct
36 Partially correct 141 ms 10028 KB Output is partially correct
37 Correct 120 ms 10008 KB Output is correct
38 Partially correct 119 ms 9752 KB Output is partially correct
39 Correct 186 ms 11352 KB Output is correct
40 Correct 207 ms 11568 KB Output is correct
41 Correct 138 ms 11292 KB Output is correct
42 Partially correct 175 ms 11528 KB Output is partially correct