# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1251912 | aritro_ | Finding Routers (IOI20_routers) | C++20 | 0 ms | 0 KiB |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
const int MOD=1000000007;
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define fraction(x); cout.unsetf(ios::floatfield); cout.precision(x); cout.setf(ios::fixed,ios::floatfield);
#define file(); freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
static int l, n, q;
static std::vector<int> p;
static std::vector<int> answer;
static int queries = 0;
int use_detector(int x)
{
queries++;
assert(x >= 0 && x <= l);
std::vector<int>::iterator left, right;
right = std::upper_bound(p.begin(), p.end(), x);
left = std::prev(right);
if (right == p.end()) {
return n - 1;
} else if ((x - *left) <= (*right - x)){
return std::distance(p.begin(), left);
} else {
return std::distance(p.begin(), right);
}
}
vector<int> find_routers(int mx, int n, int q){
//call with: use_detector(x);
//solve for: 2 routers
int l=0,r=mx,mid;
int ans=0;
while(l<=r){
mid=(l+r)/2;
int tem=use_detector(mid);
if(tem==0) ans=mid,l=mid+1;
else r=mid-1;
}
//cout<<"ANS: "<<(((ans+3)/2)+ans)+1<<endl;
return {0,(((ans+1)/2)+ans)+1};
}