結果
| 問題 |
No.2561 みんな大好きmod 998
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-12-02 15:02:41 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 180 ms / 4,000 ms |
| コード長 | 1,865 bytes |
| コンパイル時間 | 2,126 ms |
| コンパイル使用メモリ | 197,284 KB |
| 最終ジャッジ日時 | 2025-02-18 04:10:42 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 44 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
template<typename T> inline bool chmax(T &a, T b) {return ((a < b) ? (a = b, true) : (false));}
template<typename T> inline bool chmin(T &a, T b) {return ((a > b) ? (a = b, true) : (false));}
typedef long long ll;
typedef pair<ll,ll> P;
template <class BidirectionalIterator, class Compare>
bool next_combination(BidirectionalIterator first, BidirectionalIterator last, Compare comp, size_t r) {
BidirectionalIterator subset = first + r;
BidirectionalIterator src = subset;
BidirectionalIterator dst = subset;
if (first == last || first == subset || last == subset) {
return false;
}
while (first != src) {
src--;
if (comp(*src, *(last - 1))) {
while (*src >= *dst) {
dst++;
}
iter_swap(src, dst);
rotate(src + 1, dst + 1, last);
rotate(subset, subset + (last - dst) - 1, last);
return true;
}
}
rotate(first, subset, last);
return false;
}
template <class BidirectionalIterator>
bool next_combination(BidirectionalIterator first, BidirectionalIterator last, size_t r) {
using value_type = typename std::iterator_traits<BidirectionalIterator>::value_type;
return next_combination(first, last, std::less<value_type>(), r);
}
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
rep(i,n) cin >> a[i];
ll ans = 0, cnt = 0;
vector<int> per(n);
rep(i,n) per[i] = i;
do {
ll sum = 0;
rep(i,k) {
sum += a[per[i]];
}
if(sum % 998244353 <= sum % 998) {
ans++;
}
cnt++;
} while(next_combination(per.begin(),per.end(),k));
//cout << cnt << endl;
cout << ans % 998 << endl;
return 0;
}