結果

問題 No.47 ポケットを叩くとビスケットが2倍
ユーザー yukyuyukyu
提出日時 2021-03-15 22:41:43
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,017 bytes
コンパイル時間 5,171 ms
コンパイル使用メモリ 140,672 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 01:43:46
合計ジャッジ時間 5,867 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 0 ms
5,376 KB
testcase_05 AC 0 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 0 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 0 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 0 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;
use std::str::FromStr;

fn main() {
    exec(read());
}

fn exec(i: i64) {
    println!(
        "{}",
        match i {
            1 => 0,
            _ => count_tap(i),
        }
    );
}

fn count_tap(i: i64) -> i64 {
    let i_bin = format!("{:b}", i);
    let count_pow = binary_string_len(&i_bin) - 1;
    let a = pow_two(count_pow, 1);
    if i - a == 0 {
        return count_pow;
    } else {
        count_pow + 1
    }
}

fn binary_string_len(s: &String) -> i64 {
    s.len() as i64
}

fn pow_two(i: i64, mut acc: i64) -> i64 {
    if i == 0 {
        return acc;
    } else {
        acc = acc * 2;
        pow_two(i - 1, acc)
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
0