結果

問題 No.2561 みんな大好きmod 998
ユーザー あさくちあさくち
提出日時 2023-12-02 15:17:48
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 2,218 bytes
コンパイル時間 1,525 ms
コンパイル使用メモリ 182,832 KB
実行使用メモリ 14,720 KB
最終ジャッジ日時 2023-12-02 15:18:03
合計ジャッジ時間 8,080 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 221 ms
14,720 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 TLE -
testcase_04 -- -
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 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// use itertools::Itertools;

const MOD_998: usize = 998;
const MOD_998244353: usize = 998244353;

fn main() {
    let (n, k) = input_tuple::<usize>();
    let a = input_vec::<usize>();

    let mut result = 0_usize;

    // println!("{:?}", combination(n, k));

    // for combination in (0..n).combinations(k) {
    for combination in combination(n, k) {
        let mut s_998 = 0_usize;
        let mut s_998244353 = 0_usize;

        for i in combination {
            s_998 += a[i];
            s_998 %= MOD_998;

            s_998244353 += a[i];
            s_998244353 %= MOD_998244353;
        }

        if s_998244353 <= s_998 {
            result += 1;
            result %= MOD_998;
        }
    }

    println!("{}", result);
}

fn combination(n: usize, k: usize) -> Vec<Vec<usize>> {
    let mut result = Vec::new();

    rec(n, k, 0, &mut Vec::new(), &mut result);

    result
}

fn rec(n: usize, k: usize, index: usize, candi: &mut Vec<bool>, result: &mut Vec<Vec<usize>>) {
    if index == n {
        let mut candi_2 = Vec::new();

        for i in 0..n {
            if candi[i] {
                candi_2.push(i);
            }
        }

        if candi_2.len() == k {
            result.push(candi_2);
        }

        return;
    }

    candi.push(true);
    rec(n, k, index + 1, candi, result);
    candi.pop();

    candi.push(false);
    rec(n, k, index + 1, candi, result);
    candi.pop();
}

fn input_tuple<T>() -> (T, T)
where
    T: std::str::FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let stdin = std::io::stdin();

    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf = buf.trim_end().to_owned();

    let mut iter = buf.split_whitespace();

    let n = iter.next().unwrap().parse().unwrap();
    let m = iter.next().unwrap().parse().unwrap();

    (n, m)
}

fn input_vec<T>() -> Vec<T>
where
    T: std::str::FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let stdin = std::io::stdin();

    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf = buf.trim_end().to_owned();

    let iter = buf.split_whitespace();

    let line = iter.map(|x| x.parse().unwrap()).collect();

    line
}
0