結果

問題 No.2078 魔抜けなパープル
ユーザー phsplsphspls
提出日時 2022-12-27 23:44:57
言語 Rust
(1.77.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 825 bytes
コンパイル時間 13,637 ms
コンパイル使用メモリ 378,672 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 01:44:44
合計ジャッジ時間 14,631 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 8 ms
5,248 KB
testcase_02 AC 7 ms
5,376 KB
testcase_03 AC 7 ms
5,376 KB
testcase_04 AC 6 ms
5,376 KB
testcase_05 AC 6 ms
5,376 KB
testcase_06 AC 12 ms
5,376 KB
testcase_07 AC 6 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const INF: usize = 1usize << 60;

fn solve() -> usize {
    let mut xa = String::new();
    std::io::stdin().read_line(&mut xa).ok();
    let xa: Vec<usize> = xa.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let x = xa[0];
    let a = xa[1];
    let mut result = INF;
    for times in 1..=a {
        let rest = a % times; 
        let damage = a / times;
        let total = x * times + damage.pow(2) * (times - rest) + (damage+1).pow(2) * rest;
        result = result.min(total);
    }
    result
}

fn main() {
    let mut t = String::new();
    std::io::stdin().read_line(&mut t).ok();
    let t: usize = t.trim().parse().unwrap();
    let mut result = Vec::with_capacity(t);
    for _ in 0..t {
        result.push(solve());
    }
    for &v in result.iter() {
        println!("{}", v);
    }
}
0