結果

問題 No.2561 みんな大好きmod 998
ユーザー SpicaSpica
提出日時 2023-12-02 14:54:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 4,000 ms
コード長 2,244 bytes
コンパイル時間 4,372 ms
コンパイル使用メモリ 264,084 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-02 14:54:39
合計ジャッジ時間 6,335 ms
ジャッジサーバーID
(参考情報)
judge9 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 4 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 52 ms
6,676 KB
testcase_04 AC 50 ms
6,676 KB
testcase_05 AC 51 ms
6,676 KB
testcase_06 AC 51 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 1 ms
6,676 KB
testcase_11 AC 9 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 51 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 1 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 37 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 1 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 11 ms
6,676 KB
testcase_27 AC 51 ms
6,676 KB
testcase_28 AC 15 ms
6,676 KB
testcase_29 AC 6 ms
6,676 KB
testcase_30 AC 14 ms
6,676 KB
testcase_31 AC 27 ms
6,676 KB
testcase_32 AC 7 ms
6,676 KB
testcase_33 AC 5 ms
6,676 KB
testcase_34 AC 51 ms
6,676 KB
testcase_35 AC 5 ms
6,676 KB
testcase_36 AC 5 ms
6,676 KB
testcase_37 AC 3 ms
6,676 KB
testcase_38 AC 9 ms
6,676 KB
testcase_39 AC 15 ms
6,676 KB
testcase_40 AC 14 ms
6,676 KB
testcase_41 AC 9 ms
6,676 KB
testcase_42 AC 15 ms
6,676 KB
testcase_43 AC 3 ms
6,676 KB
testcase_44 AC 7 ms
6,676 KB
testcase_45 AC 37 ms
6,676 KB
testcase_46 AC 6 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long; // -2^63 ~ 2^63-1 (9.2*10^18)
using ull = unsigned long long; // 0 ~ 2^64-1 (1.8*10^19)
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for (int i = (m); (i) < int (n); i++)
#define all(v) v.begin(), v.end()
#define bit(n) (1ll<<(n)) // 2^n
#define sz(x) ((int)(x).size())
#define fi first
#define se second
template<class T> using maxpq = priority_queue<T>;
template<class T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll llINF = 1000000000000000000;
void YesNo(bool flag){
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}
// 多次元vector生成
template<ll idx = 0, ll n, class T>
auto make_vec(const ll (&d)[n], T&& init) noexcept {
    if constexpr (idx < n) return std::vector(d[idx], make_vec<idx + 1>(d, std::forward<T>(init)));
    else return init;
}
template<class T, ll idx = 0, ll n>
auto make_vec(const ll (&d)[n], const T& init = {}) noexcept {
    if constexpr (idx < n) return std::vector(d[idx], make_vec<idx + 1>(d, init));
    else return init;
}
// auto 変数名 = make_vec<型>({a, b, ...}, 初期値);

int main(){
    ll N, K;
    cin >> N >> K;
    vector<ll> a(N);
    rep(i, N){
        cin >> a[i];
    }

    ll ans = 0;
    function<void(vector<int>&)> dfs = [&](vector<int> &A){
	// 数列の長さが N に達したら打ち切り
	    if (A.size() == K) {
	        // 処理
            ll S = 0;
            rep(i, K){
                S += a[A[i]];
            }
            //cout << S << endl;
            if(S%998244353 <= S%998) ans++;
	        return;
	    }
	
	    // rep2(v, Aの最後の要素, M)とすればAが狭義単調増加などの場合も対応できる
	    // Aが空の場合に注意
	    int prev_last = (A.empty() ? 0 : A.back()+1);
	    rep2(v, prev_last, N){
	        A.push_back(v);
	        dfs(A);
	        A.pop_back();
	    }
    };

    vector<int> A;
    dfs(A);
    cout << ans%998 << endl;
}
0