Submission #933952

# Submission time Handle Problem Language Result Execution time Memory
933952 2024-02-26T15:32:52 Z kim Highway Tolls (IOI18_highway) C++17
82 / 100
184 ms 24184 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;
int vis[90005];
int tour[90005];

int solve1(int U){
    int id=0;
    queue<int> q;
    q.emplace(U);
    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=dist,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 i;
        }
    }
}
int solve2(int U){
    int id=0;
    queue<int> q;
    q.emplace(U);
    for(int i=0;i<n;++i) vis[i]=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=dist,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){
        graph[i].clear();
        if(tour[i]==l) ans.eb(i);
    }
    for(int i=0;i<m;++i){
        auto &[u,v]=edge[i];
        if(tour[u]<=l&&tour[v]<=l) graph[u].eb(v,i),graph[v].eb(u,i);
    }
    return ans.back();
}
void solve3(int U){
    queue<pii> q;
    q.emplace(U,0);
    for(int i=0;i<n;++i) vis[i]=-1;
    vis[U]=0;
    vector<int> tmp2(tmp.size(),1);
    vector<pii> vec;
    while(q.size()){
        auto [u,ok]=q.front(); q.pop();
        for(auto &[v,id]:graph[u]){
            if(vis[v]!=-1) continue;
            int ok2=ok|(v==ans[0]);
            vis[v]=vis[u]+1;
            if(vis[v]<dist) q.emplace(v,ok2), tmp2[id]=0;
            else if(vis[v]==dist&&ok2) vec.eb(v,id);
        }
    }
    int l=0,r=(int)vec.size()-1;
    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;
    solve3(solve2(solve1(0)));
    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 'int solve1(int)':
highway.cpp:35:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |         int mid=l+r>>1;
      |                 ~^~
highway.cpp: In function 'int solve2(int)':
highway.cpp:69:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   69 |         int mid=l+r>>1;
      |                 ~^~
highway.cpp: In function 'void solve3(int)':
highway.cpp:107:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  107 |         int mid=l+r>>1;
      |                 ~^~
highway.cpp: In function 'int solve1(int)':
highway.cpp:20:16: warning: control reaches end of non-void function [-Wreturn-type]
   20 |     queue<int> q;
      |                ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3096 KB Output is correct
2 Correct 1 ms 3096 KB Output is correct
3 Correct 1 ms 3092 KB Output is correct
4 Correct 1 ms 3096 KB Output is correct
5 Correct 1 ms 3096 KB Output is correct
6 Correct 1 ms 3096 KB Output is correct
7 Correct 1 ms 2904 KB Output is correct
8 Correct 1 ms 3092 KB Output is correct
9 Correct 1 ms 3096 KB Output is correct
10 Correct 1 ms 3092 KB Output is correct
11 Correct 1 ms 3096 KB Output is correct
12 Correct 1 ms 2904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3156 KB Output is correct
2 Correct 11 ms 3788 KB Output is correct
3 Correct 142 ms 9632 KB Output is correct
4 Correct 105 ms 9388 KB Output is correct
5 Correct 133 ms 9840 KB Output is correct
6 Correct 90 ms 9608 KB Output is correct
7 Correct 98 ms 10076 KB Output is correct
8 Correct 142 ms 9392 KB Output is correct
9 Correct 130 ms 9876 KB Output is correct
10 Correct 109 ms 9624 KB Output is correct
11 Correct 94 ms 9236 KB Output is correct
12 Correct 108 ms 9260 KB Output is correct
13 Correct 113 ms 8792 KB Output is correct
14 Correct 82 ms 9264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 3972 KB Output is correct
2 Correct 20 ms 4516 KB Output is correct
3 Correct 27 ms 5084 KB Output is correct
4 Correct 97 ms 8800 KB Output is correct
5 Correct 106 ms 8792 KB Output is correct
6 Correct 85 ms 8796 KB Output is correct
7 Correct 73 ms 8876 KB Output is correct
8 Correct 72 ms 8788 KB Output is correct
9 Correct 65 ms 9100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3160 KB Output is correct
2 Correct 16 ms 4044 KB Output is correct
3 Correct 72 ms 8100 KB Output is correct
4 Correct 98 ms 9656 KB Output is correct
5 Correct 85 ms 9404 KB Output is correct
6 Correct 103 ms 9860 KB Output is correct
7 Correct 82 ms 9620 KB Output is correct
8 Correct 127 ms 9616 KB Output is correct
9 Correct 126 ms 10064 KB Output is correct
10 Correct 108 ms 9632 KB Output is correct
11 Correct 137 ms 9264 KB Output is correct
12 Correct 120 ms 9256 KB Output is correct
13 Correct 129 ms 9256 KB Output is correct
14 Correct 135 ms 9496 KB Output is correct
15 Correct 77 ms 9616 KB Output is correct
16 Correct 99 ms 9888 KB Output is correct
17 Correct 127 ms 9252 KB Output is correct
18 Correct 128 ms 9272 KB Output is correct
19 Correct 118 ms 9388 KB Output is correct
20 Correct 91 ms 8792 KB Output is correct
21 Correct 90 ms 9848 KB Output is correct
22 Correct 83 ms 10112 KB Output is correct
23 Correct 135 ms 10160 KB Output is correct
24 Correct 116 ms 10116 KB Output is correct
25 Correct 110 ms 8904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4036 KB Output is correct
2 Correct 13 ms 4120 KB Output is correct
3 Correct 163 ms 10072 KB Output is correct
4 Correct 121 ms 11052 KB Output is correct
5 Correct 179 ms 11716 KB Output is correct
6 Correct 153 ms 11724 KB Output is correct
7 Correct 157 ms 11928 KB Output is correct
8 Runtime error 170 ms 24184 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 3824 KB Output is correct
2 Correct 14 ms 4068 KB Output is correct
3 Correct 114 ms 10360 KB Output is correct
4 Correct 158 ms 10572 KB Output is correct
5 Correct 168 ms 11052 KB Output is correct
6 Correct 163 ms 12188 KB Output is correct
7 Correct 111 ms 10212 KB Output is correct
8 Correct 112 ms 10540 KB Output is correct
9 Correct 102 ms 10848 KB Output is correct
10 Correct 139 ms 12176 KB Output is correct
11 Correct 141 ms 12112 KB Output is correct
12 Correct 170 ms 12164 KB Output is correct
13 Correct 130 ms 11344 KB Output is correct
14 Correct 126 ms 11620 KB Output is correct
15 Correct 112 ms 10860 KB Output is correct
16 Correct 140 ms 11364 KB Output is correct
17 Correct 124 ms 11068 KB Output is correct
18 Correct 184 ms 11208 KB Output is correct
19 Correct 178 ms 11768 KB Output is correct
20 Correct 137 ms 12060 KB Output is correct
21 Correct 155 ms 12212 KB Output is correct
22 Correct 152 ms 12208 KB Output is correct
23 Correct 145 ms 12396 KB Output is correct
24 Correct 148 ms 12668 KB Output is correct
25 Correct 177 ms 12204 KB Output is correct
26 Correct 137 ms 11744 KB Output is correct
27 Correct 156 ms 10304 KB Output is correct
28 Correct 108 ms 10724 KB Output is correct
29 Correct 90 ms 10016 KB Output is correct
30 Correct 125 ms 10064 KB Output is correct
31 Correct 133 ms 10720 KB Output is correct
32 Correct 126 ms 10200 KB Output is correct
33 Correct 118 ms 10620 KB Output is correct
34 Correct 96 ms 10312 KB Output is correct
35 Correct 86 ms 10000 KB Output is correct
36 Correct 104 ms 10176 KB Output is correct
37 Correct 94 ms 10360 KB Output is correct
38 Correct 104 ms 10328 KB Output is correct
39 Correct 178 ms 11960 KB Output is correct
40 Correct 155 ms 12376 KB Output is correct
41 Correct 148 ms 11884 KB Output is correct
42 Correct 157 ms 11916 KB Output is correct