結果

問題 No.2561 みんな大好きmod 998
ユーザー may17
提出日時 2023-12-02 15:06:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 258 ms / 4,000 ms
コード長 625 bytes
コンパイル時間 2,090 ms
コンパイル使用メモリ 199,088 KB
最終ジャッジ日時 2025-02-18 04:15:44
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 44
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
//const ll mod = 1000000007;
const int mod = 998244353;
ll n, k, a[39];
int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++)cin >> a[i];
	vector<int>v;
	for (int i = 1; i <= k; i++)v.push_back(1);
	for (int i = k + 1; i <= n; i++)v.push_back(0);
	sort(v.begin(), v.end());
	ll ans = 0;
	do {
		ll sum = 0;
		for (int i = 0; i < v.size(); i++) {
			if (v[i] == 1)sum += a[i + 1];
		}
		if (sum % mod <= sum % 998LL)ans++;
	} while (next_permutation(v.begin(), v.end()));
	cout << ans%998LL << endl;
}
0