結果

問題 No.2429 Happiest Tabehodai Ways
ユーザー 👑 chro_96chro_96
提出日時 2023-08-19 17:13:46
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 3,421 bytes
コンパイル時間 416 ms
コンパイル使用メモリ 34,236 KB
実行使用メモリ 17,536 KB
最終ジャッジ日時 2024-05-07 00:13:18
合計ジャッジ時間 3,246 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 437 ms
17,536 KB
testcase_01 AC 5 ms
17,408 KB
testcase_02 AC 6 ms
17,536 KB
testcase_03 AC 6 ms
17,536 KB
testcase_04 AC 6 ms
17,408 KB
testcase_05 AC 6 ms
17,536 KB
testcase_06 AC 5 ms
17,536 KB
testcase_07 AC 7 ms
17,536 KB
testcase_08 AC 6 ms
17,408 KB
testcase_09 AC 6 ms
17,536 KB
testcase_10 AC 6 ms
17,408 KB
testcase_11 AC 7 ms
17,536 KB
testcase_12 AC 5 ms
17,536 KB
testcase_13 AC 7 ms
17,536 KB
testcase_14 AC 6 ms
17,536 KB
testcase_15 AC 9 ms
17,408 KB
testcase_16 AC 6 ms
17,408 KB
testcase_17 AC 6 ms
17,536 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 6 ms
17,536 KB
testcase_21 AC 5 ms
17,408 KB
testcase_22 AC 7 ms
17,536 KB
testcase_23 AC 5 ms
17,408 KB
testcase_24 AC 7 ms
17,536 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 6 ms
17,536 KB
testcase_29 WA -
testcase_30 AC 10 ms
17,536 KB
testcase_31 AC 6 ms
17,536 KB
testcase_32 WA -
testcase_33 AC 11 ms
17,536 KB
testcase_34 AC 15 ms
17,536 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 8 ms
17,536 KB
testcase_38 AC 7 ms
17,536 KB
testcase_39 AC 8 ms
17,536 KB
testcase_40 AC 8 ms
17,536 KB
testcase_41 AC 46 ms
17,536 KB
testcase_42 AC 9 ms
17,536 KB
testcase_43 AC 6 ms
17,408 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][501] = {};
  
  long long comb[1001][1001] = {};
  int max = -1;

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