結果

問題 No.2561 みんな大好きmod 998
ユーザー neko_the_shadow
提出日時 2024-02-16 15:15:51
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 1,030 bytes
コンパイル時間 12,630 ms
コンパイル使用メモリ 402,960 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-09-28 19:17:53
合計ジャッジ時間 16,787 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43 WA * 1
権限があれば一括ダウンロードができます

ソースコード

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| (1i128 << i, i, 1)).collect::<Vec<_>>();
    while !stack.is_empty() {
        let (bit, cur, tot) = stack.pop().unwrap();
        if tot == 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]) % 998244352;
                }
            }
            if t2 <= t1 {
                c = (c + 1) % 998;
            }
            continue;
        }
        for nxt in cur + 1..n {
            stack.push((bit | (1 << nxt), nxt, tot + 1));
        }
    }
    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