Submission #1039646

# Submission time Handle Problem Language Result Execution time Memory
1039646 2024-07-31T06:53:27 Z vjudge1 Highway Tolls (IOI18_highway) C++17
51 / 100
113 ms 13508 KB
#include "highway.h"
#include<bits/stdc++.h>
#define K 1<<17
using namespace std;
int bfspos[2][K],bfspar[2][K],bfspari[2][K],bfsdis[2][K];
vector<pair<int,int>>adj[K];
void bfs(int n,int i){
    queue<int>q;
    int CC=0;
    memset(bfsdis[i],-1,sizeof *bfspos);
    q.push(n);
    bfsdis[i][n]=0;
    bfspar[i][n]=-1;
    while(q.size()){
        int x=q.front(),d=bfsdis[i][x];
        q.pop(); bfspos[i][x]=++CC;
        for(auto [j,k]:adj[x]) if(bfsdis[i][j]<0)
            bfspar[i][j]=x,bfspari[i][j]=k,
            bfsdis[i][j]=d+1,q.push(j);
    }
}
int indd;
int whicho(int pivot,int N,int ind,int M,vector<int>v,long long D,int spec){
    indd=ind;
    sort(v.begin(),v.end(),[](int a,int b){
        return bfspos[indd][a]<bfspos[indd][b];
    });
    int l=1,r=v.size()-1,res=1;
    while(l<=r){
        int mid=l+r>>1;
        vector<int>V(M,1);
        V[spec]=0;
        for(int i=mid;i<v.size();i++) {
            if(bfspar[ind][v[i]]!=pivot)
                if(!V[bfspari[ind][bfspar[ind][v[i]]]])
                    continue;
            V[bfspari[ind][v[i]]]=0;
        }
        if(ask(V)<D)
            l=res=mid+1;
        else r=mid-1;
    }
    return v[res-1];
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
    int M=U.size();
    for(int i=0;i<M;i++)
        adj[U[i]].push_back({V[i],i}),
        adj[V[i]].push_back({U[i],i});
    long long D=ask(vector<int>(M,0))/A;
    int res=1e9,l=1,r=M;
    while(l<=r){
        int mid=l+r>>1;
        vector<int>v(M);
        for(int i=0;i<mid;i++)
            v[i]=1;
        if(ask(v)>D*A)
            res=r=mid-1;
        else l=mid+1;
    }
    int a=U[res],b=V[res];
    bfs(a,0);
    bfs(b,1);
    vector<int>sta,stb;
    for(int i=0;i<N;i++)
        if(bfsdis[0][i]<bfsdis[1][i])
            sta.push_back(i);
        else if(bfsdis[0][i]-bfsdis[1][i])
            stb.push_back(i);
    answer(whicho(a,N,0,M,sta,D*B-B+A,res),
            whicho(b,N,1,M,stb,D*B-B+A,res));
}

Compilation message

highway.cpp: In function 'int whicho(int, int, int, int, std::vector<int>, long long int, int)':
highway.cpp:30:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |         int mid=l+r>>1;
      |                 ~^~
highway.cpp:33:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for(int i=mid;i<v.size();i++) {
      |                       ~^~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:53:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   53 |         int mid=l+r>>1;
      |                 ~^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4440 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 2 ms 4440 KB Output is correct
5 Correct 2 ms 4440 KB Output is correct
6 Correct 2 ms 4380 KB Output is correct
7 Correct 2 ms 4440 KB Output is correct
8 Correct 2 ms 4440 KB Output is correct
9 Correct 2 ms 4440 KB Output is correct
10 Correct 2 ms 4440 KB Output is correct
11 Correct 2 ms 4440 KB Output is correct
12 Correct 2 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 10 ms 5496 KB Output is correct
3 Correct 91 ms 12556 KB Output is correct
4 Correct 90 ms 12544 KB Output is correct
5 Correct 96 ms 12556 KB Output is correct
6 Correct 87 ms 12552 KB Output is correct
7 Correct 92 ms 12728 KB Output is correct
8 Correct 103 ms 12732 KB Output is correct
9 Correct 88 ms 12564 KB Output is correct
10 Correct 88 ms 12568 KB Output is correct
11 Correct 101 ms 12168 KB Output is correct
12 Correct 93 ms 12072 KB Output is correct
13 Correct 98 ms 11996 KB Output is correct
14 Correct 107 ms 11972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 5444 KB Output is correct
2 Correct 16 ms 6232 KB Output is correct
3 Correct 27 ms 7800 KB Output is correct
4 Correct 72 ms 12020 KB Output is correct
5 Correct 87 ms 12004 KB Output is correct
6 Correct 72 ms 12488 KB Output is correct
7 Correct 72 ms 11984 KB Output is correct
8 Correct 71 ms 12152 KB Output is correct
9 Correct 84 ms 12060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4440 KB Output is correct
2 Correct 11 ms 5388 KB Output is correct
3 Correct 76 ms 10780 KB Output is correct
4 Correct 94 ms 12776 KB Output is correct
5 Correct 94 ms 12560 KB Output is correct
6 Correct 94 ms 12544 KB Output is correct
7 Correct 97 ms 12576 KB Output is correct
8 Correct 103 ms 12608 KB Output is correct
9 Correct 99 ms 12552 KB Output is correct
10 Correct 99 ms 12560 KB Output is correct
11 Correct 99 ms 11980 KB Output is correct
12 Correct 93 ms 11992 KB Output is correct
13 Correct 99 ms 12040 KB Output is correct
14 Correct 97 ms 12068 KB Output is correct
15 Correct 98 ms 12540 KB Output is correct
16 Correct 96 ms 12568 KB Output is correct
17 Correct 95 ms 11996 KB Output is correct
18 Correct 94 ms 11976 KB Output is correct
19 Correct 94 ms 12568 KB Output is correct
20 Correct 92 ms 11980 KB Output is correct
21 Correct 78 ms 13280 KB Output is correct
22 Correct 76 ms 13508 KB Output is correct
23 Correct 85 ms 13000 KB Output is correct
24 Correct 90 ms 12808 KB Output is correct
25 Correct 96 ms 12144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 5464 KB Output is correct
2 Correct 13 ms 5464 KB Output is correct
3 Correct 104 ms 12888 KB Output is correct
4 Incorrect 113 ms 13360 KB Output is incorrect: {s, t} is wrong.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 5464 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -