Problem:
マンハッタンでは，道路がx 座標またはy 座標が整数のところに通っている．すぬけ君の家とすめけ君の家はどちらも道路上にあり，直線距離(ユークリッド距離) はちょうど
d
である．すぬけ君の家からすめけ君の家まで道路に沿って移動するときの最短距離として考えられる最大値を求めよ．
Constraints
0 <
d
≤ 10
d
は小数点以下ちょうど三桁まで与えられる
Input
d
Output
答えを一行に出力せよ．絶対誤差または相対誤差が
10
−9
以下のとき正答と判定される．
Sample Input 1
1.000
Sample Output 1
2.000000000000
Sample Input 2
2.345
Sample Output 2
3.316330803765

Submitted solutions:

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

int main() {
    double d;
    cin >> d;
    long double ans = d;
    for(long double i = 0; i*i <= d*d; i += 0.00001) {
        long double e = sqrt(d*d-i*i);
        if((int)round(i*100000)%100000 == 0) {
            ans = max(ans,i+1);
        }
        ans = max(ans,i+e);
    }
    cout << fixed << setprecision(18) << ans << endl;
}
accuracy: 0.8823529411764706
time_ms: 10
memory_kb: 3604
final_rank: 3

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

int main() {
    double d;
    cin >> d;
    long double ans = d;
    for(long double i = 1; i*i <= d*d; i += 0.00001) {
        long double e = sqrt(d*d-i*i);
        if((int)round(i*100000)%100000 == 0) {
            ans = max(ans,i+1);
        }
        ans = max(ans,i+e);
    }
    cout << fixed << setprecision(18) << ans << endl;
}
accuracy: 0.35294117647058826
time_ms: 10
memory_kb: 3512
final_rank: 4

code_snippet: /* C++ */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef pair<ll, ll> pint;
const ll MOD = 1000000007;
const ll INF = 922337203685477580;
#define rep(i, n) for(ll i = (ll)0; i < (ll)(n); i++)
#define Rep(i, s, t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265358979323846
#define ifYN(x) cout << (x ? "Yes" : "No") << "\n"
ll dx[4] = {-1, 1, 0, 0};
ll dy[4] = {0, 0, -1, 1};

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

ll Len(ll n) {
  if (n == 0) return 1;
  ll s = 0;
  while (n != 0) s++, n /= 10;
  return s;
}

ll Sint(ll n) {
  ll ans = 0;
  while (n != 0) ans += n % 10, n /= 10;
  return ans;
}

ll Svec(vector<ll> v){
  ll n = 0;
  rep(i, (ll)v.size()) n += v[i];
  return n;
}

ll GCD(ll a, ll b) {
  return b ? GCD(b, a % b) : a;
}

ll LCM(ll a, ll b){
  return a / GCD(a, b) * b;
}

ll POW(ll a, ll n, ll mod = INF) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

void dis(vector<ll> V) {
  rep(i, V.size()) cout << (i ? " " : "") << V[i];
  cout << endl;
}

void dis2(vector<vector<ll> > v) {
  rep (i, v.size()) {
    rep (j, v[0].size()) cout << v[i][j] << ' ';
    cout << endl;
  }
}

bool cmp(pint a, pint b) { return a.second < b.second; }

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ld D; cin >> D;
  ll nd = D;
  ld ans = nd + 1;
  for (ld i = 0; i <= D; i += 0.000001) {
    chmax(ans, i + sqrt(D * D - i * i));
  }
  cout << fixed << setprecision(10) << ans << endl;
}
accuracy: 1
time_ms: 40
memory_kb: 3308
final_rank: 2

code_snippet: #include <iostream>
#include <complex>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <map>

using namespace std;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
double d;
double f(double t) {
    double res = 0;
    for (int i = 0; i <= 10; i++) {
        if (d * d - i * i + 0.0001 >= 0) {
            double x = sqrt(d * d - i * i) + t;
            chmax(res, min(t + i + x, t - x + i));
        }
    }
    for (int j = -10; j <= 10; j++) {
        if (d * d - (j - t) * (j - t) + 0.0001 >= 0) {
            double y = sqrt(d * d - (j - t) * (j - t));
            chmax(res, abs(j - t) + y);
        }
    }
    return res;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> d;
    double l = 0, r = 0.50;
    for (int i = 0; i < 100000; i++) {
        double m1 = (l * 2 + r) / 3, m2 = (l + r * 2) / 3;
        if (f(m1) < f(m2)) {
            l = m1;
        }
        else {
            r = m2;
        }
    }

    int t = d * 1000 + 0.1;
    double ans = f((l + r) / 2);
    chmax(ans, (double)(t / 1000 + 1));
    cout << fixed << setprecision(15) << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3576
final_rank: 1