結果

問題 No.2561 みんな大好きmod 998
ユーザー takumi152takumi152
提出日時 2023-12-02 14:50:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 4,000 ms
コード長 973 bytes
コンパイル時間 812 ms
コンパイル使用メモリ 86,992 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2023-12-02 14:50:29
合計ジャッジ時間 2,234 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod_small = 998;
const ll mod_large = 998244353;

ll solve(vector<int> &idx, int next_begin, int sum_small, int sum_large, const int n, const int k, const vector<ll> &a) {
  if ((int) idx.size() == k) {
    if (sum_large <= sum_small) return 1;
    else return 0;
  }
  ll ans = 0;
  for (int i = next_begin; i < n; i++) {
    idx.push_back(i);
    ans += solve(idx, i + 1, (sum_small + a[i]) % mod_small, (sum_large + a[i]) % mod_large, n, k, a);
    idx.pop_back();
  }
  return ans;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (auto &x: a) cin >> x;

  vector<int> idx;
  ll ans = solve(idx, 0, 0, 0, n, k, a);

  cout << ans % mod_small << endl;

  return 0;
}
0