結果
問題 | No.2561 みんな大好きmod 998 |
ユーザー | あさくち |
提出日時 | 2023-12-02 15:40:01 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 702 ms / 4,000 ms |
コード長 | 2,810 bytes |
コンパイル時間 | 15,007 ms |
コンパイル使用メモリ | 376,784 KB |
実行使用メモリ | 317,568 KB |
最終ジャッジ日時 | 2024-09-26 19:07:06 |
合計ジャッジ時間 | 24,040 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 30 ms
14,592 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 702 ms
317,568 KB |
testcase_04 | AC | 674 ms
317,568 KB |
testcase_05 | AC | 673 ms
317,568 KB |
testcase_06 | AC | 680 ms
317,568 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 96 ms
43,136 KB |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 696 ms
317,568 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 1 ms
5,376 KB |
testcase_18 | AC | 1 ms
5,376 KB |
testcase_19 | AC | 487 ms
227,328 KB |
testcase_20 | AC | 1 ms
5,376 KB |
testcase_21 | AC | 1 ms
5,376 KB |
testcase_22 | AC | 1 ms
5,376 KB |
testcase_23 | AC | 1 ms
5,376 KB |
testcase_24 | AC | 1 ms
5,376 KB |
testcase_25 | AC | 1 ms
5,376 KB |
testcase_26 | AC | 125 ms
58,496 KB |
testcase_27 | AC | 688 ms
317,568 KB |
testcase_28 | AC | 176 ms
78,336 KB |
testcase_29 | AC | 50 ms
22,912 KB |
testcase_30 | AC | 174 ms
76,544 KB |
testcase_31 | AC | 330 ms
160,512 KB |
testcase_32 | AC | 72 ms
34,176 KB |
testcase_33 | AC | 49 ms
22,912 KB |
testcase_34 | AC | 674 ms
317,568 KB |
testcase_35 | AC | 42 ms
21,632 KB |
testcase_36 | AC | 42 ms
21,632 KB |
testcase_37 | AC | 21 ms
10,496 KB |
testcase_38 | AC | 96 ms
43,136 KB |
testcase_39 | AC | 168 ms
76,544 KB |
testcase_40 | AC | 160 ms
76,544 KB |
testcase_41 | AC | 96 ms
43,136 KB |
testcase_42 | AC | 175 ms
78,208 KB |
testcase_43 | AC | 21 ms
10,496 KB |
testcase_44 | AC | 70 ms
31,616 KB |
testcase_45 | AC | 483 ms
227,328 KB |
testcase_46 | AC | 59 ms
27,264 KB |
ソースコード
// 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(&(0..n).collect::<Vec<_>>(), k)); // for combination in (0..n).combinations(k) { for combination in combination(&(0..n).collect::<Vec<_>>(), 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(elems: &Vec<usize>, r: usize) -> Vec<Vec<usize>> { // vector<vector<T>> v{}; let mut v = Vec::new(); // vector<T> v1(r); let mut v1 = vec![0; r]; // int n = elems.size(); let n = elems.len(); rec(n, r, &elems, &mut v, &mut v1, 0, 0, 0); return v; } fn rec( n: usize, r: usize, elems: &Vec<usize>, v: &mut Vec<Vec<usize>>, v1: &mut Vec<usize>, bit: usize, now: usize, num_decided: usize, ) { if num_decided == r { // int index = 0; let mut index = 0; // for(int i=0; i<n;i++){ // if(bit&(1<<i)){ // v1[index] = elems[i]; // index++; // } // } for i in 0..n { if bit & (1 << i) > 0 { v1[index] = elems[i]; index += 1; } } // v.push_back(v1); v.push(v1.clone()); return; } // if(now == n)return; if now == n { return; } rec( n, r, &elems, v, v1, bit + (1 << now), now + 1, num_decided + 1, ); rec(n, r, &elems, v, v1, bit, now + 1, num_decided); } 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 }