結果

問題 No.2561 みんな大好きmod 998
ユーザー neko_the_shadowneko_the_shadow
提出日時 2024-02-16 15:31:42
言語 Rust
(1.77.0)
結果
AC  
実行時間 358 ms / 4,000 ms
コード長 1,035 bytes
コンパイル時間 868 ms
コンパイル使用メモリ 182,640 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-16 15:31:49
合計ジャッジ時間 6,864 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 13 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 328 ms
6,676 KB
testcase_04 AC 340 ms
6,676 KB
testcase_05 AC 324 ms
6,676 KB
testcase_06 AC 353 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 1 ms
6,676 KB
testcase_10 AC 1 ms
6,676 KB
testcase_11 AC 48 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 AC 1 ms
6,676 KB
testcase_14 AC 1 ms
6,676 KB
testcase_15 AC 329 ms
6,676 KB
testcase_16 AC 1 ms
6,676 KB
testcase_17 AC 1 ms
6,676 KB
testcase_18 AC 1 ms
6,676 KB
testcase_19 AC 238 ms
6,676 KB
testcase_20 AC 1 ms
6,676 KB
testcase_21 AC 1 ms
6,676 KB
testcase_22 AC 1 ms
6,676 KB
testcase_23 AC 1 ms
6,676 KB
testcase_24 AC 1 ms
6,676 KB
testcase_25 AC 0 ms
6,676 KB
testcase_26 AC 66 ms
6,676 KB
testcase_27 AC 358 ms
6,676 KB
testcase_28 AC 87 ms
6,676 KB
testcase_29 AC 25 ms
6,676 KB
testcase_30 AC 73 ms
6,676 KB
testcase_31 AC 159 ms
6,676 KB
testcase_32 AC 37 ms
6,676 KB
testcase_33 AC 26 ms
6,676 KB
testcase_34 AC 331 ms
6,676 KB
testcase_35 AC 26 ms
6,676 KB
testcase_36 AC 24 ms
6,676 KB
testcase_37 AC 10 ms
6,676 KB
testcase_38 AC 49 ms
6,676 KB
testcase_39 AC 81 ms
6,676 KB
testcase_40 AC 85 ms
6,676 KB
testcase_41 AC 49 ms
6,676 KB
testcase_42 AC 90 ms
6,676 KB
testcase_43 AC 10 ms
6,676 KB
testcase_44 AC 35 ms
6,676 KB
testcase_45 AC 248 ms
6,676 KB
testcase_46 AC 31 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::stdin;

fn main() {
    let nk = read();
    let n = nk[0];
    let k = nk[1];
    let a = read();

    // bit, cur, tot
    let mut c = 0;
    let mut stack = (0..n).map(|i| (1u128 << i, i)).collect::<Vec<_>>();
    while !stack.is_empty() {
        let (bit, cur) = stack.pop().unwrap();
        if bit.count_ones() as usize == k {
            let mut t1 = 0;
            let mut t2 = 0;
            for i in 0..n {
                if bit & (1 << i) != 0 {
                    t1 = (t1 + a[i]) % 998;
                    t2 = (t2 + a[i]) % 998244353;
                }
            }
            if t2 <= t1 {
                c = (c + 1) % 998;
            }
            continue;
        }
        for nxt in cur + 1..n {
            stack.push((bit | (1 << nxt), nxt));
        }
    }
    println!("{}", c);
}

fn read() -> Vec<usize> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.split_whitespace()
        .map(|token| token.parse().unwrap())
        .collect::<Vec<_>>()
}
0