結果

問題 No.2420 Simple Problem
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2023-08-12 14:04:38
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,858 bytes
コンパイル時間 14,755 ms
コンパイル使用メモリ 378,516 KB
実行使用メモリ 34,176 KB
最終ジャッジ日時 2024-04-30 04:54:59
合計ジャッジ時間 18,633 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 148 ms
27,520 KB
testcase_28 AC 152 ms
27,648 KB
testcase_29 AC 148 ms
27,520 KB
testcase_30 AC 178 ms
27,648 KB
testcase_31 AC 150 ms
27,648 KB
testcase_32 AC 0 ms
5,376 KB
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut sc = Scanner::new();
    let n = sc.usize();

    // √a + √b < x
    // a + b + 2√ab < x^2
    // 2√ab < x^2 - a - b
    // 4ab < (x^2 - a - b)^2

    let mut ans = Vec::with_capacity(n);
    for _ in 0..n {
        let a = sc.i128();
        let b = sc.i128();

        let mut l = 0;
        let mut r = 10_000_000_000;
        while l + 1 < r {
            let m = (l + r) / 2;
            if 4*a*b < (m*m - a - b).saturating_mul(m*m - a - b) {
                r = m;
            } else {
                l = m;
            }
        }
        ans.push(r);
    }

    println!("{}", ans.iter().map(|&x| x.to_string()).collect::<Vec<_>>().join("\n"));
}

struct Scanner { s : std::collections::VecDeque<String> } #[allow(unused)] impl Scanner { fn new() -> Self { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); Self { s : s.split_whitespace().map(|s| s.to_string()).collect() } } fn reload(&mut self) -> () { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); self.s = s.split_whitespace().map(|s| s.to_string()).collect(); } fn usize(&mut self) -> usize { self.input() } fn usize1(&mut self) -> usize { self.input::<usize>() - 1 } fn isize(&mut self) -> isize { self.input() } fn i32(&mut self) -> i32 { self.input() } fn i64(&mut self) -> i64 { self.input() } fn i128(&mut self) -> i128 { self.input() } fn u8(&mut self) -> u8 { self.input() } fn u32(&mut self) -> u32 { self.input() } fn u64(&mut self) -> u64 { self.input() } fn u128(&mut self) -> u128 { self.input() } fn edge(&mut self) -> (usize, usize) { (self.usize1(), self.usize1()) } fn edges(&mut self, m : usize) -> Vec<(usize, usize)> { let mut e = Vec::with_capacity(m); for _ in 0..m { e.push(self.edge()); } e } fn wedge<T:std::str::FromStr>(&mut self) -> (usize, usize, T) { (self.usize1(), self.usize1(), self.input()) } fn wedges<T:std::str::FromStr>(&mut self, m : usize) -> Vec<(usize, usize, T)> { let mut e = Vec::with_capacity(m); for _ in 0..m { e.push(self.wedge()); } e } fn input<T>(&mut self) -> T where T: std::str::FromStr { if self.s.is_empty() { self.reload(); } if let Some(head) = self.s.pop_front() { head.parse::<T>().ok().unwrap() } else { panic!() } } fn tuple<T, U>(&mut self) -> (T, U) where T: std::str::FromStr, U: std::str::FromStr { (self.input(), self.input()) } fn vec<T>(&mut self, n: usize) -> Vec<T> where T: std::str::FromStr { if self.s.is_empty() { self.reload(); } self.s.drain(..n).map(|s| s.parse::<T>().ok().unwrap() ).collect::<Vec<T>>() } fn nvec<T>(&mut self) -> Vec<T> where T: std::str::FromStr { let n : usize = self.input(); self.vec(n) } fn chars(&mut self) -> Vec<char> { let s : String = self.input(); s.chars().collect() } fn bytes(&mut self) -> Vec<u8> { let s : String = self.input(); s.bytes().collect() } }
0