結果
| 問題 |
No.2561 みんな大好きmod 998
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-12-02 15:17:48 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,218 bytes |
| コンパイル時間 | 19,791 ms |
| コンパイル使用メモリ | 377,776 KB |
| 実行使用メモリ | 14,720 KB |
| 最終ジャッジ日時 | 2024-09-26 18:24:47 |
| 合計ジャッジ時間 | 21,024 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | TLE * 1 -- * 43 |
ソースコード
// 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
}