답안 #1005891

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1005891 2024-06-23T07:35:49 Z irmuun 통행료 (IOI18_highway) C++17
51 / 100
216 ms 262144 KB
#include<bits/stdc++.h>
#include "highway.h"
 
using namespace std;
 
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

const int maxn=9e4+5;

int n,m,a,b;
vector<int>u,v;

vector<pair<int,int>>adj[maxn];
vector<int>dep(maxn,0),edge(maxn,0),w,L,R,edges;
int cur=0;

void dfs(int x,int p){
    if(cur==0) L.pb(x);
    else R.pb(x);
    for(auto [y,e]:adj[x]){
        if(y!=p){
            if(cur==0){
                edges.pb(e);
            }
            dep[y]=dep[x]+1;
            edge[y]=e;
            dfs(y,x);
        }
    }
}

void find_pair(int N,vector<int>U,vector<int>V,int A, int B){
    n=N,u=U,v=V,a=A,b=B;
    m=u.size();
    
    for(int i=0;i<m;i++){
        adj[u[i]].pb({v[i],i});
        adj[v[i]].pb({u[i],i});
    }
    
    w.resize(m);
    fill(all(w),0);
    ll C=ask(w);
    int d=C/A;
    int l=0,r=m-1;
    while(l<r){
        int mid=(l+r)/2;
        fill(all(w),0);
        for(int i=0;i<=mid;i++){
            w[i]=1;
        }
        if(ask(w)>C){
            r=mid;
        }
        else{
            l=mid+1;
        }
    }
    int v1=u[l],v2=v[l];
    dep[v1]=0;
    dep[v2]=0;
    dfs(v1,v2);
    cur=1;
    dfs(v2,v1);
    fill(all(w),0);
    for(auto e:edges){
        w[e]=1;
    }
    ll cost=ask(w);
    int dep1=(cost-C)/(ll)(b-a);
    int dep2=d-dep1-1;
    vector<int>ver;
    for(auto i:L){
        if(dep[i]==dep1){
            ver.pb(i);
        }
    }
    l=0,r=ver.size()-1;
    while(l<r){
        int mid=(l+r)/2;
        fill(all(w),0);
        for(int i=0;i<=mid;i++){
            w[edge[ver[i]]]=1;
        }
        if(ask(w)>C){
            r=mid;
        }
        else{
            l=mid+1;
        }
    }
    int S=ver[l];
    ver.clear();
    for(auto i:R){
        if(dep[i]==dep2){
            ver.pb(i);
        }
    }
    l=0,r=ver.size()-1;
    while(l<r){
        int mid=(l+r)/2;
        fill(all(w),0);
        for(int i=0;i<=mid;i++){
            w[edge[ver[i]]]=1;
        }
        if(ask(w)>C){
            r=mid;
        }
        else{
            l=mid+1;
        }
    }
    int T=ver[l];
    answer(S,T);
    return;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3160 KB Output is correct
2 Correct 1 ms 3160 KB Output is correct
3 Correct 1 ms 3160 KB Output is correct
4 Correct 1 ms 3160 KB Output is correct
5 Correct 1 ms 3160 KB Output is correct
6 Correct 1 ms 3160 KB Output is correct
7 Correct 1 ms 3160 KB Output is correct
8 Correct 1 ms 3160 KB Output is correct
9 Correct 1 ms 3160 KB Output is correct
10 Correct 1 ms 3160 KB Output is correct
11 Correct 1 ms 3160 KB Output is correct
12 Correct 2 ms 3160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3160 KB Output is correct
2 Correct 9 ms 3856 KB Output is correct
3 Correct 74 ms 10004 KB Output is correct
4 Correct 78 ms 9624 KB Output is correct
5 Correct 69 ms 9668 KB Output is correct
6 Correct 64 ms 9668 KB Output is correct
7 Correct 74 ms 9724 KB Output is correct
8 Correct 65 ms 9664 KB Output is correct
9 Correct 66 ms 9960 KB Output is correct
10 Correct 75 ms 9928 KB Output is correct
11 Correct 77 ms 10688 KB Output is correct
12 Correct 66 ms 11452 KB Output is correct
13 Correct 68 ms 10964 KB Output is correct
14 Correct 68 ms 11216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4440 KB Output is correct
2 Correct 14 ms 5732 KB Output is correct
3 Correct 21 ms 7308 KB Output is correct
4 Correct 60 ms 13620 KB Output is correct
5 Correct 52 ms 13688 KB Output is correct
6 Correct 60 ms 14780 KB Output is correct
7 Correct 63 ms 16100 KB Output is correct
8 Correct 69 ms 13976 KB Output is correct
9 Correct 63 ms 14832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3160 KB Output is correct
2 Correct 9 ms 3844 KB Output is correct
3 Correct 50 ms 8392 KB Output is correct
4 Correct 68 ms 9672 KB Output is correct
5 Correct 70 ms 9868 KB Output is correct
6 Correct 62 ms 9664 KB Output is correct
7 Correct 66 ms 9956 KB Output is correct
8 Correct 68 ms 9968 KB Output is correct
9 Correct 74 ms 10188 KB Output is correct
10 Correct 73 ms 9932 KB Output is correct
11 Correct 76 ms 10960 KB Output is correct
12 Correct 71 ms 11452 KB Output is correct
13 Correct 61 ms 11492 KB Output is correct
14 Correct 75 ms 10972 KB Output is correct
15 Correct 69 ms 9696 KB Output is correct
16 Correct 65 ms 9572 KB Output is correct
17 Correct 76 ms 10944 KB Output is correct
18 Correct 67 ms 11472 KB Output is correct
19 Correct 68 ms 9920 KB Output is correct
20 Correct 60 ms 11756 KB Output is correct
21 Correct 56 ms 10472 KB Output is correct
22 Correct 67 ms 11064 KB Output is correct
23 Correct 78 ms 10360 KB Output is correct
24 Correct 79 ms 10688 KB Output is correct
25 Correct 79 ms 15392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 216 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 174 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -