結果

問題 No.1010 折って重ねて
ユーザー phspls
提出日時 2020-03-29 00:03:21
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,272 bytes
コンパイル時間 11,914 ms
コンパイル使用メモリ 381,764 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-01-02 12:27:01
合計ジャッジ時間 13,273 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::{HashSet, VecDeque};

fn main() {
    let mut xyh: String = String::new();
    std::io::stdin().read_line(&mut xyh).ok();
    let xyh: Vec<usize> = xyh.trim().split_whitespace().map(|i| i.parse().unwrap()).collect();
    let x: usize = xyh[0] as usize * 1000;
    let y: usize = xyh[1] as usize * 1000;
    let h = xyh[2];
    let mut cands: VecDeque<(usize, usize, usize)> = VecDeque::new();
    let mut used: HashSet<(usize, usize, usize)> = HashSet::new();
    let mut target: (usize, usize, usize) = (0, 0, h);
    cands.push_back(target);
    used.insert(target);
    while cands.len() > 0 {
        target = cands.pop_front().unwrap();
        if x > target.2 * 2usize.pow(target.0 as u32) {
            let next: (usize, usize, usize) = (target.0 + 1, target.1, target.2 * 2);
            if !cands.contains(&next) {
                cands.push_back(next);
                used.insert(next);
            }
        }
        if y > target.2 * 2usize.pow(target.1 as u32) {
            let next: (usize, usize, usize) = (target.0, target.1 + 1, target.2 * 2);
            if !cands.contains(&next) {
                cands.push_back(next);
                used.insert(next);
            }
        }
    }
    println!("{}", target.0 + target.1);
}
0