結果

問題 No.2429 Happiest Tabehodai Ways
ユーザー 👑 chro_96chro_96
提出日時 2023-08-19 14:41:01
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1,147 ms / 2,000 ms
コード長 2,214 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 31,180 KB
実行使用メモリ 17,584 KB
最終ジャッジ日時 2023-09-03 03:05:58
合計ジャッジ時間 4,178 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,147 ms
17,468 KB
testcase_01 AC 5 ms
17,548 KB
testcase_02 AC 5 ms
17,392 KB
testcase_03 AC 5 ms
17,576 KB
testcase_04 AC 5 ms
17,460 KB
testcase_05 AC 5 ms
17,500 KB
testcase_06 AC 5 ms
17,464 KB
testcase_07 AC 4 ms
17,456 KB
testcase_08 AC 6 ms
17,396 KB
testcase_09 AC 6 ms
17,504 KB
testcase_10 AC 5 ms
17,520 KB
testcase_11 AC 5 ms
17,456 KB
testcase_12 AC 5 ms
17,500 KB
testcase_13 AC 5 ms
17,528 KB
testcase_14 AC 5 ms
17,460 KB
testcase_15 AC 7 ms
17,396 KB
testcase_16 AC 5 ms
17,520 KB
testcase_17 AC 5 ms
17,516 KB
testcase_18 AC 5 ms
17,460 KB
testcase_19 AC 6 ms
17,520 KB
testcase_20 AC 6 ms
17,516 KB
testcase_21 AC 6 ms
17,456 KB
testcase_22 AC 5 ms
17,508 KB
testcase_23 AC 5 ms
17,392 KB
testcase_24 AC 5 ms
17,508 KB
testcase_25 AC 5 ms
17,584 KB
testcase_26 AC 5 ms
17,392 KB
testcase_27 AC 5 ms
17,528 KB
testcase_28 AC 5 ms
17,400 KB
testcase_29 AC 13 ms
17,580 KB
testcase_30 AC 6 ms
17,456 KB
testcase_31 AC 5 ms
17,584 KB
testcase_32 AC 5 ms
17,460 KB
testcase_33 AC 9 ms
17,464 KB
testcase_34 AC 8 ms
17,456 KB
testcase_35 AC 7 ms
17,576 KB
testcase_36 AC 23 ms
17,460 KB
testcase_37 AC 7 ms
17,560 KB
testcase_38 AC 6 ms
17,400 KB
testcase_39 AC 6 ms
17,584 KB
testcase_40 AC 6 ms
17,480 KB
testcase_41 AC 11 ms
17,556 KB
testcase_42 AC 41 ms
17,460 KB
testcase_43 AC 5 ms
17,576 KB
権限があれば一括ダウンロードができます

ソースコード

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;
  for (int i = k; i > 0; 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 = 0; q*i <= i*p+j; q++) {
                  cnt[i*p+j][q] = 0LL;
                }
              }
              for (int q = 0; q*(i+1) <= 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