제출 #394402

#제출 시각아이디문제언어결과실행 시간메모리
394402Theo830Highway Tolls (IOI18_highway)C++17
0 / 100
308 ms262148 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1e18+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
#include "highway.h"
ll par[90005] = {0};
ll depth[90005] = {0};
vector<vll>adj;
void dfs(ll u,ll p){
    par[u] = p;
    for(auto x:adj[u]){
        if(x != p){
            depth[x] = depth[u] + 1;
            dfs(x,u);
        }
    }
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B){
    adj.assign(N+1,vll());
    ll m = U.size();
    f(i,0,m){
        adj[U[i]].pb(V[i]);
        adj[V[i]].pb(U[i]);
    }
    dfs(0,-1);
    ll s = 0,t = 0;
    vector<int>w(m);
    w.assign(m,0);
    ll di = ask(w) / A;
    ll n = N;
    ll l = 0,r = n-2;
    while(l < r){
        ll mid = (l+r)/2;
        w.assign(m,0);
        f(i,l,mid){
            w[l] = 1;
        }
        ll g = ask(w);
        if(g == di * B){
            r = mid - 1;
        }
        else if(g == di * A){
            l = mid;
        }
        else{
            ll b = (g - (di * A)) / (B - A);
            ll a = di - b;
            s = mid - b;
            t = mid + a - 1;
            break;
        }
    }
    if(s == t){
        s = l;
        t = l + 1;
    }
    answer(s,t);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...