結果

問題 No.2429 Happiest Tabehodai Ways
ユーザー 👑 chro_96chro_96
提出日時 2023-08-19 10:54:07
言語 C
(gcc 12.3.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,436 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 31,688 KB
実行使用メモリ 26,100 KB
最終ジャッジ日時 2023-09-03 03:05:54
合計ジャッジ時間 6,626 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main () {
  int n = 0;
  int k = 0;
  int c[1000] = {};
  int d[1000] = {};

  int res = 0;
  
  long long ans = 0LL;
  long long mod_num = 998244353LL;
  
  int d_max_cnt[1001][2] = {};
  int d_max[1001] = {};
  long long cnt[1001][1001] = {};
  
  long long comb[1001][1001] = {};
  int max = -1;
 
  res = scanf("%d", &n);
  res = scanf("%d", &k);
  for (int i = 0; i < n; i++) {
    res = scanf("%d", c+i);
  }
  for (int i = 0; i < n; i++) {
    res = scanf("%d", d+i);
  }
  
  for (int i = 0; i <= k; i++) {
    comb[i][0] = 1LL;
    comb[i][i] = 1LL;
    for (int j = 1; j < i; j++) {
      comb[i][j] = (comb[i-1][j-1]+comb[i-1][j])%mod_num;
    }
  }
  
  for (int i = 0; i < n; i++) {
    if (d_max_cnt[c[i]][0] < d[i]) {
      d_max_cnt[c[i]][0] = d[i];
      d_max_cnt[c[i]][1] = 1;
    } else if (d_max_cnt[c[i]][0] == d[i]) {
      d_max_cnt[c[i]][1]++;
    }
  }
  
  for (int i = 0; i <= k; i++) {
    d_max[i] = -1;
  }
  
  d_max[0] = 0;
  cnt[0][0] = 1LL;
  if (d_max_cnt[1][0] > 0) {
    long long pow = 1LL;
    for (int i = 1; i <= k; i++) {
      pow *= (long long)d_max_cnt[1][1];
      pow %= mod_num;
      d_max[i] = i*d_max_cnt[1][0];
      cnt[i][i] = pow;
    }
  }
  for (int i = 2; i <= k; i++) {
    if (d_max_cnt[i][1] > 0) {
      for (int j = k-i; j >= 0; j--) {
        if (d_max[j] >= 0) {
          long long pow = 1LL;
          for (int p = 1; i*p+j <= k; p++) {
            pow *= (long long)d_max_cnt[i][1];
            pow %= mod_num;
            if (d_max[i*p+j] <= d_max[j]+d_max_cnt[i][0]*p) {
              if (d_max[i*p+j] < d_max[j]+d_max_cnt[i][0]*p) {
                d_max[i*p+j] = d_max[j]+d_max_cnt[i][0]*p;
                for (int q = i*p+j; q*i >= i*p+j; q--) {
                  cnt[i*p+j][q] = 0LL;
                }
              }
              for (int q = j; q*i >= j; q--) {
                if (cnt[j][q] > 0LL) {
                  long long tmp = (cnt[j][q]*comb[p+q][p])%mod_num;
                  cnt[i*p+j][p+q] += (tmp*pow)%mod_num;
                  cnt[i*p+j][p+q] %= mod_num;
                }
              }
            }
          }
        }
      }
    }
  }
  
  for (int i = 0; i <= k; i++) {
    if (d_max[i] > max) {
      max = d_max[i];
      ans = 0LL;
    }
    if (d_max[i] == max) {
      for (int j = 0; j <= i; j++) {
        ans += cnt[i][j];
      }
    }
  }
  
  printf("%d\n%lld\n", max, ans%mod_num);
  return 0;
}
0