結果

問題 No.47 ポケットを叩くとビスケットが2倍
ユーザー Yusuke WadaYusuke Wada
提出日時 2020-09-03 15:48:55
言語 Rust
(1.77.0)
結果
AC  
実行時間 152 ms / 5,000 ms
コード長 1,420 bytes
コンパイル時間 24,171 ms
コンパイル使用メモリ 401,916 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-03 00:24:05
合計ジャッジ時間 15,740 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 152 ms
6,812 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,812 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 78 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 95 ms
6,940 KB
testcase_09 AC 13 ms
6,940 KB
testcase_10 AC 130 ms
6,940 KB
testcase_11 AC 71 ms
6,940 KB
testcase_12 AC 58 ms
6,940 KB
testcase_13 AC 48 ms
6,944 KB
testcase_14 AC 101 ms
6,940 KB
testcase_15 AC 15 ms
6,940 KB
testcase_16 AC 30 ms
6,940 KB
testcase_17 AC 42 ms
6,940 KB
testcase_18 AC 12 ms
6,940 KB
testcase_19 AC 3 ms
6,944 KB
testcase_20 AC 34 ms
6,940 KB
testcase_21 AC 20 ms
6,940 KB
testcase_22 AC 43 ms
6,944 KB
testcase_23 AC 87 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn getline() -> String {
    let mut __ret = String::new();
    std::io::stdin().read_line(&mut __ret).ok();
    return __ret;
}

fn getline_as_u64() -> u64 {
    let l = getline();
    let nlv: Vec<_> = l.trim().split(' ').collect();
    nlv[0].parse::<u64>().unwrap()
}

fn main() {
    let n: u64 = getline_as_u64();
    let mut remain = Some(n);
    let mut pocket: u64 = 1;
    let mut hit = 0;

    loop {
        // まずはポケットを叩いてみるッス
        let next = pocket * 2;
        match remain {
            Some(1) => remain = None,
            Some(some_remain) => {
                if some_remain == next {
                    // ポケットの中身と残数が同じになったらポンとやって終了
                    hit = hit + 1;
                    remain = None;
                } else if some_remain > next {
                    // それでも残数のほうが多い場合、もう一度やる
                    hit = hit + 1;
                    pocket = next
                } else {
                    // ポケットの中身のほうが多くなってしまう場合、そのままたたかずにポケットの中身をひとつ減らす
                    remain = Some(some_remain - 1);
                    pocket = pocket - 1;
                }
            }
            _ => {
                break;
            }
        }
    }

    println!("{}", hit)
}
0