結果

問題 No.2420 Simple Problem
ユーザー shop_oneshop_one
提出日時 2023-08-12 14:21:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,447 ms / 2,000 ms
コード長 1,133 bytes
コンパイル時間 1,280 ms
コンパイル使用メモリ 134,336 KB
実行使用メモリ 40,448 KB
最終ジャッジ日時 2023-12-24 13:06:19
合計ジャッジ時間 43,501 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
6,676 KB
testcase_01 AC 542 ms
19,712 KB
testcase_02 AC 13 ms
6,676 KB
testcase_03 AC 190 ms
10,624 KB
testcase_04 AC 1,107 ms
33,408 KB
testcase_05 AC 680 ms
23,168 KB
testcase_06 AC 1,428 ms
40,448 KB
testcase_07 AC 1,419 ms
40,448 KB
testcase_08 AC 1,423 ms
40,448 KB
testcase_09 AC 1,402 ms
40,448 KB
testcase_10 AC 1,421 ms
40,448 KB
testcase_11 AC 1,412 ms
40,448 KB
testcase_12 AC 1,424 ms
40,448 KB
testcase_13 AC 1,418 ms
40,448 KB
testcase_14 AC 1,411 ms
40,448 KB
testcase_15 AC 1,428 ms
40,448 KB
testcase_16 AC 1,415 ms
40,448 KB
testcase_17 AC 1,416 ms
40,448 KB
testcase_18 AC 1,415 ms
40,448 KB
testcase_19 AC 1,421 ms
40,448 KB
testcase_20 AC 1,428 ms
40,448 KB
testcase_21 AC 1,424 ms
40,448 KB
testcase_22 AC 1,429 ms
40,448 KB
testcase_23 AC 1,431 ms
40,448 KB
testcase_24 AC 1,427 ms
40,448 KB
testcase_25 AC 1,447 ms
40,448 KB
testcase_26 AC 9 ms
6,676 KB
testcase_27 AC 882 ms
26,880 KB
testcase_28 AC 894 ms
26,880 KB
testcase_29 AC 894 ms
26,880 KB
testcase_30 AC 894 ms
26,880 KB
testcase_31 AC 883 ms
26,880 KB
testcase_32 AC 9 ms
6,676 KB
testcase_33 AC 521 ms
19,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<cmath>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
map<ll, double> mp;
double calc(ll v) {
  auto itr = mp.find(v);
  if (itr != mp.end()) {
    return itr->second;
  }
  double s = 1, e = v;
  for (int i=0;i<100;i++) {
    double h = (s+e)/2;
    if (h*h < v) {
      s = h;
    } else {
      e = h;
    }
  }
  mp[v] = (s+e)/2;
  return (s+e)/2;
}
signed main(){
  const ll MAX = 1e9+2;
  map<ll,ll> p;
  for (ll i=1;i*i<=MAX;i++) {
    p[i*i] = i;
  }
  init_io();
  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  for (int i=0;i<n;i++){
    cin >> a[i] >> b[i];
    ll ans;
    auto ia = p.find(a[i]), ib = p.find(b[i]);
    if (ia != p.end() && ib != p.end()) {
      ans = ia->second + ib->second + 1;
    } else {
      ans = ceil(calc(a[i]) + calc(b[i]));
    }
    cout << ans << endl;
  }
}
0