結果

問題 No.2429 Happiest Tabehodai Ways
ユーザー 👑 chro_96chro_96
提出日時 2023-08-18 23:18:05
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 2,148 bytes
コンパイル時間 600 ms
コンパイル使用メモリ 32,188 KB
実行使用メモリ 17,704 KB
最終ジャッジ日時 2024-05-06 18:00:27
合計ジャッジ時間 2,644 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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