結果

問題 No.2429 Happiest Tabehodai Ways
ユーザー 👑 chro_96chro_96
提出日時 2023-08-19 15:30:10
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1,001 ms / 2,000 ms
コード長 2,902 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 32,572 KB
実行使用メモリ 25,388 KB
最終ジャッジ日時 2023-09-03 03:06:03
合計ジャッジ時間 4,421 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,001 ms
25,288 KB
testcase_01 AC 8 ms
25,308 KB
testcase_02 AC 7 ms
25,272 KB
testcase_03 AC 7 ms
25,344 KB
testcase_04 AC 7 ms
25,268 KB
testcase_05 AC 7 ms
25,268 KB
testcase_06 AC 7 ms
25,284 KB
testcase_07 AC 8 ms
25,268 KB
testcase_08 AC 7 ms
25,264 KB
testcase_09 AC 7 ms
25,172 KB
testcase_10 AC 8 ms
25,224 KB
testcase_11 AC 7 ms
25,224 KB
testcase_12 AC 7 ms
25,292 KB
testcase_13 AC 9 ms
25,268 KB
testcase_14 AC 7 ms
25,352 KB
testcase_15 AC 9 ms
25,176 KB
testcase_16 AC 7 ms
25,372 KB
testcase_17 AC 7 ms
25,224 KB
testcase_18 AC 7 ms
25,224 KB
testcase_19 AC 8 ms
25,284 KB
testcase_20 AC 7 ms
25,176 KB
testcase_21 AC 8 ms
25,268 KB
testcase_22 AC 7 ms
25,336 KB
testcase_23 AC 7 ms
25,380 KB
testcase_24 AC 7 ms
25,340 KB
testcase_25 AC 7 ms
25,340 KB
testcase_26 AC 7 ms
25,176 KB
testcase_27 AC 7 ms
25,284 KB
testcase_28 AC 7 ms
25,296 KB
testcase_29 AC 34 ms
25,272 KB
testcase_30 AC 9 ms
25,388 KB
testcase_31 AC 7 ms
25,384 KB
testcase_32 AC 8 ms
25,348 KB
testcase_33 AC 12 ms
25,272 KB
testcase_34 AC 15 ms
25,372 KB
testcase_35 AC 8 ms
25,296 KB
testcase_36 AC 70 ms
25,376 KB
testcase_37 AC 9 ms
25,268 KB
testcase_38 AC 8 ms
25,284 KB
testcase_39 AC 8 ms
25,172 KB
testcase_40 AC 8 ms
25,268 KB
testcase_41 AC 42 ms
25,268 KB
testcase_42 AC 265 ms
25,372 KB
testcase_43 AC 7 ms
25,372 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;

  long long pow[1001][1001] = {};
  
  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 = 1; i <= k; i++) {
    if (d_max_cnt[i][1] > 0) {
      pow[i][0] = 1LL;
      for (int j = 1; j*i <= k; j++) {
        pow[i][j] = pow[i][j-1]*((long long)d_max_cnt[i][1]);
        pow[i][j] %= mod_num;
      }
    }
  }
  
  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) {
      int tmpmax = k/i;
      for (int j = k-i; j > i; j--) {
        if (d_max[j] >= 0) {
          int max = (k-j)/i;
          for (int p = 1; p <= max; p++) {
            if (d_max[i*p+j] <= d_max[j]+d_max_cnt[i][0]*p) {
              int tmpmax = j/(i+1);
              if (d_max[i*p+j] < d_max[j]+d_max_cnt[i][0]*p) {
                if (d_max[i*p+j] >= 0) {
                  for (int q = 0; q*i <= i*p+j; q++) {
                    cnt[i*p+j][q] = 0LL;
                  }
                }
                d_max[i*p+j] = d_max[j]+d_max_cnt[i][0]*p;
              }
              for (int q = 1; q <= tmpmax; q++) {
                long long tmp = (cnt[j][q]*comb[p+q][p])%mod_num;
                cnt[i*p+j][p+q] += (tmp*pow[i][p])%mod_num;
                cnt[i*p+j][p+q] %= mod_num;
              }
            }
          }
        }
      }
      for (int j = 1; j <= tmpmax; j++) {
        if (d_max[i*j] <= d_max_cnt[i][0]*j) {
          if (d_max[i*j] < d_max_cnt[i][0]*j) {
            if (d_max[i*j] >= 0) {
              for (int q = 0; q <= j; q++) {
                cnt[i*j][q] = 0LL;
              }
            }
            d_max[i*j] = d_max_cnt[i][0]*j;
          }
          cnt[i*j][j] += pow[i][j];
          cnt[i*j][j] %= 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