結果
問題 |
No.47 ポケットを叩くとビスケットが2倍
|
ユーザー |
![]() |
提出日時 | 2021-03-15 22:24:21 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,177 bytes |
コンパイル時間 | 15,129 ms |
コンパイル使用メモリ | 378,640 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-07 11:00:24 |
合計ジャッジ時間 | 14,781 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 WA * 7 |
ソースコード
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 { if i % 2 == 0 { return calculate_count_tap(i); } else { calculate_count_tap(i - 1) + 1 } } fn calculate_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") }