結果

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

ソースコード

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 += 1;
            }
            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