結果

問題 No.1869 Doubling?
ユーザー phsplsphspls
提出日時 2022-09-25 16:16:44
言語 Rust
(1.77.0)
結果
MLE  
実行時間 -
コード長 1,092 bytes
コンパイル時間 3,959 ms
コンパイル使用メモリ 137,084 KB
実行使用メモリ 813,148 KB
最終ジャッジ日時 2023-08-24 00:58:13
合計ジャッジ時間 4,807 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 673 ms
302,708 KB
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::VecDeque;


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 m == 1 {
        println!("{}", n);
        return;
    }
    if n == 1 {
        println!("{}", m);
        return;
    }
    let mut deque = VecDeque::new();
    deque.push_back((3usize, 2usize, 2usize));
    let mut cands = vec![];
    while let Some((summary, cnt, last)) = deque.pop_front() {
        if cnt == n {
            cands.push(summary);
            continue;
        }
        let inserted = last * 2 - 1 > m;
        if last * 2 <= m {
            deque.push_front((summary+last*2, cnt+1, last*2));
        } else if !inserted {
            cands.push(summary + (n - cnt));
        }
        if last * 2 - 1 <= m {
            deque.push_front((summary + last*2-1, cnt+1, last*2-1));
        } else {
            cands.push(summary + (n - cnt));
        }
    }
    println!("{}", cands.iter().max().unwrap());
}
0