結果

問題 No.1869 Doubling?
ユーザー phspls
提出日時 2022-09-25 17:05:55
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 648 bytes
コンパイル時間 12,328 ms
コンパイル使用メモリ 405,692 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-22 13:05:02
合計ジャッジ時間 13,915 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30 WA * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unnecessary parentheses around `if` condition
 --> src/main.rs:9:8
  |
9 |     if (n <= 60 && (1 << (n-1)) <= m) {
  |        ^                            ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
9 -     if (n <= 60 && (1 << (n-1)) <= m) {
9 +     if n <= 60 && (1 << (n-1)) <= m {
  |

ソースコード

diff #

fn main() {
    let mut nm = String::new();
    std::io::stdin().read_line(&mut nm).ok();
    let nm: Vec<usize> = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nm[0];
    let m = nm[1];

    if (n <= 60 && (1 << (n-1)) <= m) {
        println!("{}", (1usize << n) - 1);
    }
    let mut start = m;
    let mut stack = vec![];
    while stack.len() < n && start > 1 {
        stack.push(start);
        if start & 1 == 1 {
            start = (start+1)/2;
        } else {
            start /= 2;
        }
    }
    let result = stack.iter().sum::<usize>() + (n - stack.len()) * 1;
    println!("{}", result);
}
0