結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 19 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 491 ms
6,676 KB
testcase_04 AC 470 ms
6,676 KB
testcase_05 AC 484 ms
6,676 KB
testcase_06 AC 497 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 0 ms
6,676 KB
testcase_11 AC 68 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 485 ms
6,676 KB
testcase_16 AC 1 ms
6,676 KB
testcase_17 AC 0 ms
6,676 KB
testcase_18 AC 1 ms
6,676 KB
testcase_19 AC 367 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 1 ms
6,676 KB
testcase_26 AC 98 ms
6,676 KB
testcase_27 AC 489 ms
6,676 KB
testcase_28 AC 129 ms
6,676 KB
testcase_29 AC 36 ms
6,676 KB
testcase_30 AC 109 ms
6,676 KB
testcase_31 AC 242 ms
6,676 KB
testcase_32 AC 55 ms
6,676 KB
testcase_33 AC 35 ms
6,676 KB
testcase_34 AC 491 ms
6,676 KB
testcase_35 AC 33 ms
6,676 KB
testcase_36 AC 33 ms
6,676 KB
testcase_37 AC 15 ms
6,676 KB
testcase_38 AC 70 ms
6,676 KB
testcase_39 AC 111 ms
6,676 KB
testcase_40 AC 110 ms
6,676 KB
testcase_41 AC 70 ms
6,676 KB
testcase_42 AC 134 ms
6,676 KB
testcase_43 AC 15 ms
6,676 KB
testcase_44 AC 49 ms
6,676 KB
testcase_45 AC 341 ms
6,676 KB
testcase_46 AC 42 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).collect::<Vec<_>>();
    while !stack.is_empty() {
        let bit = 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 i in (0..n).rev() {
            if bit&(1<<i)!=0{
                break
            }
            stack.push(bit|(1<<i));
        }
    }
    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