結果

問題 No.2561 みんな大好きmod 998
ユーザー tnakao0123tnakao0123
提出日時 2023-12-03 22:41:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 603 ms / 4,000 ms
コード長 1,147 bytes
コンパイル時間 576 ms
コンパイル使用メモリ 42,176 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-03 22:41:51
合計ジャッジ時間 9,439 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 11 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 584 ms
6,676 KB
testcase_04 AC 578 ms
6,676 KB
testcase_05 AC 581 ms
6,676 KB
testcase_06 AC 576 ms
6,676 KB
testcase_07 AC 46 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 78 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 AC 13 ms
6,676 KB
testcase_14 AC 24 ms
6,676 KB
testcase_15 AC 603 ms
6,676 KB
testcase_16 AC 46 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 339 ms
6,676 KB
testcase_20 AC 5 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 1 ms
6,676 KB
testcase_25 AC 1 ms
6,676 KB
testcase_26 AC 137 ms
6,676 KB
testcase_27 AC 580 ms
6,676 KB
testcase_28 AC 245 ms
6,676 KB
testcase_29 AC 30 ms
6,676 KB
testcase_30 AC 74 ms
6,676 KB
testcase_31 AC 201 ms
6,676 KB
testcase_32 AC 393 ms
6,676 KB
testcase_33 AC 29 ms
6,676 KB
testcase_34 AC 577 ms
6,676 KB
testcase_35 AC 106 ms
6,676 KB
testcase_36 AC 107 ms
6,676 KB
testcase_37 AC 20 ms
6,676 KB
testcase_38 AC 79 ms
6,676 KB
testcase_39 AC 74 ms
6,676 KB
testcase_40 AC 73 ms
6,676 KB
testcase_41 AC 79 ms
6,676 KB
testcase_42 AC 242 ms
6,676 KB
testcase_43 AC 19 ms
6,676 KB
testcase_44 AC 47 ms
6,676 KB
testcase_45 AC 337 ms
6,676 KB
testcase_46 AC 200 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2561.cc:  No.2561 みんな大好きmod 998 - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 28;
const int MAX_M = 10;
const int MBITS = 1 << MAX_M;
const int MMSK = MBITS - 1;
const int MOD0 = 998;
const int MOD1 = 998244353;

/* typedef */

typedef long long ll;

/* global variables */

int bnums[MBITS], as[MAX_N];

/* subroutines */

inline int bitnum(int bits) {
  return
    bnums[bits & MMSK] +
    bnums[(bits >> MAX_M) & MMSK] +
    bnums[(bits >> (MAX_M * 2)) & MMSK];
}

/* main */

int main() {
  for (int bits = 1, msb = 1; bits < MBITS; bits++) {
    if ((msb << 1) <= bits) msb <<= 1;
    bnums[bits] = bnums[bits ^ msb] + 1;
  }

  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  int nbits = 1 << n, cnt = 0;
  for (int bits = 0; bits < nbits; bits++)
    if (bitnum(bits) == k) {
      ll s = 0;
      for (int i = 0, bi = 1; i < n; i++, bi <<= 1)
	if (bits & bi) s += as[i];
      int s0 = s % MOD0, s1 = s % MOD1;
      if (s1 <= s0) cnt++;
    }

  printf("%d\n", cnt % MOD0);
  return 0;
}
0