結果
| 問題 | No.2420 Simple Problem |
| コンテスト | |
| ユーザー |
shop_one
|
| 提出日時 | 2023-08-12 14:21:45 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 1,094 ms / 2,000 ms |
| コード長 | 1,133 bytes |
| 記録 | |
| コンパイル時間 | 997 ms |
| コンパイル使用メモリ | 153,956 KB |
| 実行使用メモリ | 40,576 KB |
| 最終ジャッジ日時 | 2026-07-02 02:13:49 |
| 合計ジャッジ時間 | 31,548 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 33 |
ソースコード
// 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;
}
}
shop_one