Problem:
Ruins
The Aizu Archaeological Society has set out to investigate the ruin of the ancient nation of Iwashiro, which is submerged in the Hibarra Sea. The ruin exists somewhere in the Hibara Sea. We decided to use radar to get a rough idea of the location of the ruin from the shoreline, and to estimate how many meters away from the shoreline we would have to go to investigate.
The observation points are placed on the coastline represented by the straight line as shown in the figure above, and the exploration radars are placed there. The radar can only tell us that there is the ruin within a semicircle of a certain size centered on the observation point. However, by combining multiple observation data, it is possible to narrow down the area to a smaller one.
Given some observation data, consisting of the location of the observation points and the radius indicated by the exploration radars, write a program to find out how far from the coastline we need to survey at most.
Input
The input is given in the following format.
N
x
1
r
1
x
2
r
2
:
x
N
r
N
The first line gives the number of data measured by the exploration radar
N
(1 ≤
N
≤ 100000). The following
N
lines are integers
x
i
that represents the position of the observed data
i
on the coastline in meters (0 ≤
x
i
≤ 1,000,000) and integers
r
i
that represents the number of meters within a radius of the site  (1 ≤
r
i
≤ 1,000,000). Two or more observation data with the same observation point may be given.
If there are multiple observational data given, it can be considered that there is always a point included in all of those semicircles.
Output
Outputs the actual number of meters that need to be investigated from the coastline. However, the error must not exceed plus or minus 0.001 meters. If this condition is satisfied, any number of digits after the decimal point may be displayed.
Sample Input 1
2
0 2
1 2
Sample Output 1
1.936
Sample Input 2
3
0 3
1 2
2 1
Sample Output 2
1.0
Sample Input 3
2
0 1
3 2
Sample Output 3
0.0

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
#include <cassert>
#include <numeric>
#ifdef _MSC_VER
#include <intrin.h>
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
template<typename T>
bool chmax(T & a, const T & b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll linf = 1e18;
const int dy[] = { 0,0,1,-1 }, dx[] = { 1,-1,0,0 };
int main() {
    int n; cin >> n;
    double left = -inf, right = inf;
    vector<int> x(n), r(n);
    rep(i, n) {
        cin >> x[i] >> r[i];
        chmax(left, double(x[i] - r[i]));
        chmin(right, double(x[i] + r[i]));
    }
    auto f = [&](double d) {
        double res = inf;
        rep(i, n) {
            chmin(res, sqrt((double)r[i] * r[i] - (d - x[i]) * (d - x[i])));
        }
        return res;
    };
    rep(i, 100) {
        double m1 = (left * 2 + right) / 3;
        double m2 = (left + right * 2) / 3;
        if (f(m1) < f(m2))left= m1;
        else right = m2;
    }
    printf("%.10f\n", f(left));
}
accuracy: 1
time_ms: 50
memory_kb: 4352
final_rank: 4

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
#include <cassert>
#include <numeric>
#ifdef _MSC_VER
#include <intrin.h>
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
template<typename T>
bool chmax(T & a, const T & b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll linf = 1e18;
const int dy[] = { 0,0,1,-1 }, dx[] = { 1,-1,0,0 };
int main() {
    int n; cin >> n;
    double left = -inf, right = inf;
    vector<int> x(n), r(n);
    rep(i, n) {
        cin >> x[i] >> r[i];
        chmax(left, double(x[i] - r[i]));
        chmin(right, double(x[i] + r[i]));
    }
    auto f = [&](double d) {
        double res = inf;
        rep(i, n) {
            chmin(res, sqrt(r[i] * r[i] - (d - x[i]) * (d - x[i])));
        }
        return res;
    };
    rep(i, 100) {
        double m1 = (left * 2 + right) / 3;
        double m2 = (left + right * 2) / 3;
        if (f(m1) < f(m2))left= m1;
        else right = m2;
    }
    printf("%.10f\n", f(left));
}
accuracy: 0.14285714285714285
time_ms: 100
memory_kb: 4352
final_rank: 19

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
#include <cassert>
#include <numeric>
#ifdef _MSC_VER
#include <intrin.h>
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
template<typename T>
bool chmax(T & a, const T & b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll linf = 1e18;
const int dy[] = { 0,0,1,-1 }, dx[] = { 1,-1,0,0 };
int main() {
    int n; cin >> n;
    double left = -inf, right = inf;
    vector<int> x(n), r(n);
    rep(i, n) {
        cin >> x[i] >> r[i];
        chmax(left, double(x[i] - r[i]));
        chmin(right, double(x[i] + r[i]));
    }
    auto f = [&](double d) {
        double res = inf;
        rep(i, n) {
            chmin(res, sqrt(r[i] * r[i] - (d - x[i]) * (d - x[i])));
        }
        return res;
    };
    rep(i, 100) {
        double m1 = (left * 2 + right) / 3;
        double m2 = (left + right * 2) / 3;
        if (f(m1) < f(m2))left= m1;
        else right = m2;
    }
    cout << f(left) << endl;
}
accuracy: 0.14285714285714285
time_ms: 110
memory_kb: 4480
final_rank: 20

code_snippet: #include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}


struct UnionFind{
	vector<int> data;
	int n, m;

	UnionFind(int ns, int ms) : n(ns), m(ms), data(ns + ms, INT_MIN){
		REP(i, m){
			data[i + n] = -i-1;
		}
	}

	bool unite(int a, int b){//矛盾の判定
		a = root(a), b = root(b);

		if (a == b)
			return true;

		if (data[a] != INT_MIN && data[b] != INT_MIN){
			if (data[a] != data[b]){
				return false;
			}
			else {
				if (rand() % 2)
					data[b] = a;
				else
					data[a] = b;
			}
		}
		else if (data[a] != INT_MIN)
			data[b] = a;
		else if (data[b] != INT_MIN)
			data[a] = b;
		else{
			if (rand() % 2)
				data[b] = a;
			else
				data[a] = b;
		}
		return true;
	}


	bool unitebu(int a, int b){//矛盾の判定 aをbの部活
		a = root(a);
		b += n;

		if (data[a] == data[b])
			return true;
		if (data[a] != INT_MIN)
			return false;

		data[a] = b;
		return true;
	}

	bool findset(int a, int b){
		return root(a) == root(b);
	}

	int root(int x){
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
};

signed main() {
	int n;
	cin >> n;
	vector<pair<double,double>> za(n);
	vector<int> l, r;
	REP(i, n){
		scanf("%lf %lf", &za[i].first, &za[i].second);
		l.push_back(za[i].first - za[i].second);
		r.push_back(za[i].first + za[i].second);
	}

	sort(ALL(l));
	sort(ALL(r));

	int rb = r[0], lb = l[l.size()-1];


	function<double(double)> func = [&](double pos){
		double ret = 10000000;

		REP(i, n){
			double rad = za[i].second, dis = abs(pos - za[i].first);
			ret = min(ret, sqrt(rad*rad - dis*dis));
		}

		return ret;
	};

	double x0 = lb, x3 = rb;
	REP(i, 50){
		if (x0 >= x3)
			break;
		
		double x1 = (x0+x0+x3)/3, x2 = (x0 + x3 + x3)/3;

		if (func(x1) < func(x2))
			x0 = x1;
		else
			x3 = x2;

	}

	printf("%.6lf\n", func((x0 + x3) / 2));

	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 5764
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
// #include<atcoder/all>
// using mint = atcoder::modint998244353;
using ld = long double;
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(int)(n);++i)
template<typename T>bool chmin(T&a,T b){return b<a?(a=b,1):0;}
template<typename T>bool chmax(T&a,T b){return b>a?(a=b,1):0;}
const ld EPS = 1e-10;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N;
    cin>>N;
    vector<ld> X(N),R(N);
    rep(i,N)cin>>X[i]>>R[i];

    ld ok=0;
    ld ng=1e9;
    rep(i,N) chmin(ng, R[i]);
    while(ng-ok>EPS){
        ld m=(ok+ng)/2;

        ld l=-1e9;
        ld r=1e9;
        rep(i,N){
            ld z=sqrtl(R[i]*R[i]-m*m);
            chmax(l, X[i]-z);
            chmin(r, X[i]+z);
        }
        if(l<=r) ok=m;
        else ng=m;
    }
    cout<<fixed<<setprecision(15);
    cout<<ok<<"\n";

}
accuracy: 1
time_ms: 30
memory_kb: 6784
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,N) for(ll i=0;i<N;i++)
#define pb push_back
#define all(A) A.begin(),A.end()

int main(){
    int N;cin>>N;
    vector<ld>X(N),R(N);
    ld ng = 0;
    rep(i,N){
        cin>>X[i]>>R[i];
        ng = max(ng,R[i]);
    }
    ld ok = 0;ng+=1.0;
    while(ng-ok>=0.0001){
        ld m = (ok+ng)/2.0;
        ld l = -1000000,r=2000000;
        rep(i,N){
            if(R[i]<m){
                r = l-1000;
                break;
            }
            ld d = sqrt(R[i]*R[i]-m*m);
            l = max(l,X[i]-d);
            r = min(r,X[i]+d);
        }
        if(l<=r)ok = m;
        else ng = m;
    } 
    cout<<fixed<<setprecision(10)<<ok<<endl;
}
accuracy: 1
time_ms: 60
memory_kb: 6252
final_rank: 8

code_snippet: #include <bits/stdc++.h>

using namespace std;

constexpr int N = 1e5 + 5;

double x[N], r[N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;

    for (int i = 0; i < n; ++i)
        cin >> x[i] >> r[i];

    double lb = 0, rb = 1e6;

    while (lb + 1e-9 < rb) {
        double mid = (lb + rb) / 2;
        double pl = -1e9, pr = 1e9;

        for (int i = 0; i < n; ++i) {
            if (r[i] < mid) {
                pl = 1e9, pr = -1e9;
                break;
            }

            pl = max(pl, x[i] - sqrt(r[i] * r[i] - mid * mid));
            pr = min(pr, x[i] + sqrt(r[i] * r[i] - mid * mid));
        }

        if (pl <= pr)
            lb = mid;
        else
            rb = mid;
    } 

    cout << fixed << setprecision(9) << (lb + rb) / 2;
}
accuracy: 1
time_ms: 40
memory_kb: 5072
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<pair<long double,long double>> a(n);
    pair<long double,long double> r(-1e9,1e9);
    for(int i = 0;i < n;i++){
        cin >> a[i].first >> a[i].second;
        r.first = max(r.first,a[i].first - a[i].second);
        r.second = min(r.second,a[i].first + a[i].second);
    }
    if(r.second < r.first){
        cout << 0 << endl;
        exit(0);
    }
    auto cal = [](pair<long double,long double> a,long double x) -> long double {
        long double it = abs(a.first - x);
        it = sqrt(a.second * a.second - it * it);
        return it;
    };
    auto f = [&](long double x) -> long double {
        long double res = 1e9;
        for(int i = 0;i < n;i++){
            res = min(res,cal(a[i],x));
        }
        return res;
    };
    while(abs(r.second - r.first) >= 0.00001){
        long double ml = (r.first * 2.0 + r.second) / 3.0,mr = (r.first + r.second * 2.0) / 3.0;
        if(f(ml) < f(mr)){
            r.first = ml;
        }else{
            r.second = mr;
        }
    }
    long double ans = f(r.first);
    cout << fixed << setprecision(5) << ans << endl;
}
accuracy: 1
time_ms: 90
memory_kb: 6188
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ld = long double;

int main() {
  int N;
  cin >> N;
  vector<ld> x(N), r(N), cand;
  for(int i = 0; i < N; i++) {
    cin >> x[i] >> r[i];
    cand.push_back(x[i]-r[i]);
    cand.push_back(x[i]+r[i]);
  }
  auto f = [&](ld p) -> ld {
    ld ymin = INFINITY;
    for(int i = 0; i < N; i++) {
      ymin = min(ymin, sqrt(r[i]*r[i]-(x[i]-p)*(x[i]-p)));
    }
    return ymin;
  };
  sort(cand.begin(), cand.end());
  ld L = cand[N-1], R = cand[N];
  for(int _t = 0; _t < 100; _t++) {
    ld ml = L+(R-L)/3.0;
    ld mr = R-(R-L)/3.0;
    if(f(ml) > f(mr)) R = mr;
    else L = ml;
  }
  cout << fixed << setprecision(6) << f(L) << endl;
}
accuracy: 1
time_ms: 120
memory_kb: 12148
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ld = long double;

int main() {
  int N;
  cin >> N;
  vector<ld> x(N), r(N), cand;
  for(int i = 0; i < N; i++) {
    cin >> x[i] >> r[i];
    cand.push_back(x[i]-r[i]);
    cand.push_back(x[i]+r[i]);
  }
  auto f = [&](ld p) -> pair<bool, ld> {
    int cnt = 0;
    ld ymin = INFINITY;
    for(int i = 0; i < N; i++) {
      if(x[i]-r[i] <= p && p <= x[i]+r[i]) {
        cnt++;
        ymin = min(ymin, sqrt(r[i]*r[i]-(x[i]-p)*(x[i]-p)));
      }else {
        return make_pair(false, 0);
      }
    }
    return make_pair(true, ymin);
  };
  sort(cand.begin(), cand.end());
  ld L = cand[N-1], R = cand[N];
  for(int _t = 0; _t < 100; _t++) {
    ld ml = L+(R-L)/3.0;
    ld mr = R-(R-L)/3.0;
    if(f(ml).second > f(mr).second) R = mr;
    else L = ml;
  }
  cout << fixed << setprecision(6) << f(L).second << endl;
}
accuracy: 1
time_ms: 140
memory_kb: 12276
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ld = long double;

int main() {
  int N;
  cin >> N;
  vector<ld> x(N), r(N), cand;
  for(int i = 0; i < N; i++) {
    cin >> x[i] >> r[i];
    cand.push_back(x[i]-r[i]);
    cand.push_back(x[i]+r[i]);
  }
  auto f = [&](ld p) -> pair<bool, ld> {
    int cnt = 0;
    ld ymin = INFINITY;
    for(int i = 0; i < N; i++) {
      if(x[i]-r[i] <= p && p <= x[i]+r[i]) {
        cnt++;
        ymin = min(ymin, sqrt(r[i]*r[i]-(x[i]-p)*(x[i]-p)));
      }else {
        return make_pair(false, 0);
      }
    }
    return make_pair(true, ymin);
  };
  ld L, R;
  sort(cand.begin(), cand.end());
  { // 左端を見つける
    int ok = 0, ng = N;
    while(ok+1 < ng) {
      int k = (ok+ng)/2;
      if(f(cand[N-k-1]).first) ok = k;
      else ng = k;
    }
    L = cand[N-ok-1];
  }
  { // 右端を見つける
    int ok = 0, ng = N;
    while(ok+1 < ng) {
      int k = (ok+ng)/2;
      if(f(cand[N+k]).first) ok = k;
      else ng = k;
    }
    R = cand[N+ok];
  }
  for(int _t = 0; _t < 100; _t++) {
    ld ml = L+(R-L)/3.0;
    ld mr = R-(R-L)/3.0;
    if(f(ml).second > f(mr).second) R = mr;
    else L = ml;
  }
  cout << fixed << setprecision(6) << f(L).second << endl;
}
accuracy: 1
time_ms: 140
memory_kb: 12020
final_rank: 13

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;



int n;
double x[1<<17],r[1<<17];

double calc(double now){
    double ans = 1e9;
    for(int i = 0;i<n;i++){
        double dx = x[i] - now;
        dx *= dx;
        double dy = sqrt(r[i]*r[i]-dx);
        ans = min(ans,dy);
    }
    return ans;
}

int main(){
    cin>>n;
    for(int i = 0;i<n;i++) cin>>x[i]>>r[i];
    double right = 1e9;
    double left = -1e9;
    for(int i = 0;i<n;i++){
        left = max(left,x[i]-r[i]);
        right = min(right,x[i]+r[i]);
    }
    int q = 100;
    double ans = 0;
    //cout<<left<<" "<<right<<endl;
    while(q--){
        double m1 = (right+right+left) / 3.;
        double m2 = (right+left+left) / 3.;
        double c1 = calc(m1);
        double c2 = calc(m2);
        ans = max(ans,c1);
        ans = max(ans,c2);
        if(c1>c2) left = m2;
        else right = m1;
    }
    cout<<fixed<<setprecision(20)<<ans<<endl;

}
accuracy: 1
time_ms: 70
memory_kb: 5136
final_rank: 7

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 0323.cc: Ruins
 */

#include<cstdio>
#include<cmath>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int CNT = 100;
const double DINF = 1e60;

/* typedef */

/* global variables */

int xs[MAX_N], rs[MAX_N];

/* subroutines */

bool check(int n, double y) {
  double minx = -DINF, maxx = DINF;
  for (int i = 0; i < n; i++) {
    double dx = sqrt((double)rs[i] * rs[i] - y * y);
    minx = max(minx, xs[i] - dx);
    maxx = min(maxx, xs[i] + dx);
  }
  return (minx <= maxx);
}

/* main */

int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d%d", xs + i, rs + i);

  int minr = *min_element(rs, rs + n);

  double y0 = 0.0, y1 = minr;
  for (int cnt = 0; cnt < CNT; cnt++) {
    double y = (y0 + y1) / 2;
    if (check(n, y)) y0 = y;
    else y1 = y;
  }

  printf("%.6lf\n", y0);
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3736
final_rank: 1

code_snippet: #include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
const long double EPS = 1e-7;
int main(){
  int n;cin>>n;
  vector<pair<long double,long double>> A(n);
  long double mx = 0;
  long double wmn = 1000000;
  long double wmx = 0;
  for(int i = 0; n > i; i++){
    cin>>A[i].first>>A[i].second;
    mx = max(A[i].second,mx);
    wmn = min(A[i].first,wmn);
    wmx = max(A[i].first,wmx);
  }
  long double mn = 0;
  mx+=1;
  while(mx-mn > 1e-6){
    long double ce = (mx+mn)/2;
    long double le = wmn;
    long double ri = wmx;
    for(int i = 0; n > i; i++){
      //A[i]がce以上を満たす範囲を求める
      if(A[i].second<ce){
        le = wmx+1;
        break;
      }
      long double dist = sqrt(A[i].second*A[i].second-ce*ce);
      le = max(le,A[i].first-dist);
      ri = min(ri,A[i].first+dist);
    }
    if(le<=ri){
      mn = ce;
    }else{
      mx = ce;
    }
  }
  cout << fixed << setprecision(10) << mn << endl;
}
accuracy: 1
time_ms: 60
memory_kb: 6252
final_rank: 8

code_snippet: #include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
const long double EPS = 1e-7;
int main(){
  int n;cin>>n;
  vector<pair<long double,long double>> A(n);
  long double mx = 0;
  long double wmn = 1000000;
  long double wmx = 0;
  for(int i = 0; n > i; i++){
    cin>>A[i].first>>A[i].second;
    mx = max(A[i].second,mx);
    wmn = min(A[i].first,wmn);
    wmx = max(A[i].first,wmx);
  }
  long double mn = 0;
  mx+=1;
  while(mx-mn > 1e-6){
    long double ce = (mx+mn)/2;
    long double le = wmn;
    long double ri = wmx;
    for(int i = 0; n > i; i++){
      //A[i]がce以上を満たす範囲を求める
      if(A[i].second<ce){
        le = wmx+1;
        break;
      }
      long double dist = sqrt(A[i].second*A[i].second-ce*ce);
      le = max(le,A[i].first-dist);
      ri = min(ri,A[i].first+dist);
    }
    if(le<ri+EPS){
      mn = ce;
    }else{
      mx = ce;
    }
  }
  cout << fixed << setprecision(10) << mn << endl;
}
accuracy: 0.5714285714285714
time_ms: 70
memory_kb: 6196
final_rank: 17

code_snippet: #include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
const double EPS = 1e-7;
int main(){
  int n;cin>>n;
  vector<pair<double,double>> A(n);
  double mx = 0;
  double wmn = 1000000;
  double wmx = 0;
  for(int i = 0; n > i; i++){
    cin>>A[i].first>>A[i].second;
    mx = max(A[i].second,mx);
    wmn = min(A[i].first,wmn);
    wmx = max(A[i].first,wmx);
  }
  double mn = 0;
  mx+=1;
  while(mx-mn > 1e-6){
    double ce = (mx+mn)/2;
    double le = wmn;
    double ri = wmx;
    for(int i = 0; n > i; i++){
      //A[i]がce以上を満たす範囲を求める
      if(A[i].second<ce){
        le = wmx+1;
        break;
      }
      double dist = sqrt(A[i].second*A[i].second-ce*ce);
      le = max(le,A[i].first-dist);
      ri = min(ri,A[i].first+dist);
    }
    if(le<ri+EPS){
      mn = ce;
    }else{
      mx = ce;
    }
  }
  cout << fixed << setprecision(10) << mn << endl;
}
accuracy: 0.5714285714285714
time_ms: 60
memory_kb: 4556
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
const double INF = 10000000;
int main(){
  cout << fixed << setprecision(20);
  int N;
  cin >> N;
  vector<double> x(N), r(N);
  for (int i = 0; i < N; i++){
    cin >> x[i] >> r[i];
  }
  double mn = INF;
  for (int i = 0; i < N; i++){
    mn = min(mn, r[i]);
  }
  double tv = 0, fv = mn;
  for (int i = 0; i < 50; i++){
    double mid = (tv + fv) / 2;
    double L = -INF, R = INF;
    for (int j = 0; j < N; j++){
      double d = sqrt(r[j] * r[j] - mid * mid);
      L = max(L, x[j] - d);
      R = min(R, x[j] + d);
    }
    if (L <= R){
      tv = mid;
    } else {
      fv = mid;
    }
  }
  cout << tv << endl;
}
accuracy: 1
time_ms: 70
memory_kb: 4648
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
typedef long long ll;
typedef pair<long long, long long> P;
const long long INF = 1e9;
template <typename T>
void input_arr(vector<T>& A, long long N) {
    for (long long i = 0; i < N; i++) {
        cin >> A[i];
    }
}
long long N;
vector<double>X(200000), R(200000);
double f(double x) {
    double ans = 1e13;
    for (long long i = 0; i < N; i++) {
        double d = abs(x - X[i]);
        ans = min(ans, sqrt(R[i] * R[i] - d * d));
    }
    return ans;
}
double sanbuntansaku(double L, double R) {
    double left = L, right = R;
    for (long long i = 0; i <= 100; i++) {
        if (f((left + right * 2)/3) >= f((left*2+right)/3)) {
            left = (left*2 + right) / 3;
        }
        else right = (left+ right*2) / 3;
    }
    return (left + right) * 0.5;
}
int main() {
    cin >> N;
    double l = -1e13, r = 1e13;
    for (long long i = 0; i < N; i++) {
        cin >> X[i] >> R[i];
        l=max(l, X[i]-R[i]);
        r=min(r, X[i]+R[i]);
    }
    cout << fixed << setprecision(6) << f(sanbuntansaku(l, r)) << endl;
}
accuracy: 1
time_ms: 70
memory_kb: 6164
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
typedef long long ll;
typedef pair<long long, long long> P;
const long long INF = 1e9;
template <typename T>
void input_arr(vector<T>& A, long long N) {
    for (long long i = 0; i < N; i++) {
        cin >> A[i];
    }
}
long long N;
vector<double>X(200000), R(200000);
double f(double x) {
    double ans = 1e13;
    for (long long i = 0; i < N; i++) {
        double d = abs(x - X[i]);
        ans = min(ans, sqrt(R[i] * R[i] - d * d));
    }
    return ans;
}
double sanbuntansaku(double L, double R) {
    double left = L, right = R;
    for (long long i = 0; i <= 100; i++) {
        if (f((left + right * 2)/3) >= f((left*2+right)/3)) {
            left = (left*2 + right) / 3;
        }
        else right = (left+ right*2) / 3;
    }
    return (left + right) * 0.5;
}
int main() {
    cin >> N;
    double l = -1e13, r = 1e13;
    for (long long i = 0; i < N; i++) {
        cin >> X[i] >> R[i];
        l=max(l, X[i]-R[i]);
        r=min(r, X[i]+R[i]);
    }
    cout << f(sanbuntansaku(l, r)) << endl;
}
accuracy: 0.14285714285714285
time_ms: 70
memory_kb: 6072
final_rank: 18

code_snippet: #include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pint = pair<int,int>;

double ternary(double low, double high, function<double(double)> f, int itr = 128) {
	
	for(int i = 0; i < itr; i++) {
		double c1 = (low * 2 + high) / 3;
		double c2 = (low + high * 2) / 3;
		double v1 = f(c1), v2 = f(c2);
		(v1 > v2 ? low : high) = (v1 > v2 ? c1 : c2);
	}
	return low;
}


int main()
{
	int N; cin >> N;
	vector<int> x(N), r(N);
	const int GETA = 1000000;
	for(int i = 0; i < N; i++) cin >> x[i] >> r[i], x[i] += GETA;
	
	vector<int> imos(GETA * 3 + 1);
	for(int i = 0; i < N; i++) {
		int L = x[i] - r[i];
		int R = x[i] + r[i];
		imos[L]++;
		imos[R + 1]--;
	}

	int M = imos.size();
	for(int i = 1; i < M; i++)imos[i] += imos[i - 1];
	int L = M, R = -1;
	for(int i = 0; i < M; i++) {
		if(imos[i] != N)continue;
		L = min(i, L);
		R = max(i, R);
	}

	auto f = [&](double p) {
		
		double ans = 1e9;
		for(int i = 0; i < N; i++) {
			double dist = (double)r[i] * r[i] - (double)(p - x[i]) * (p - x[i]);
			dist = sqrt(dist);
			ans = min(ans, dist);
		}
		return -ans;
	};
	
	auto argmin = ternary(L, R, f);
	cout << fixed <<setprecision(12); 
	cout << -f(argmin) << endl;
}
accuracy: 1
time_ms: 160
memory_kb: 15708
final_rank: 15