結果

問題 No.2243 Coaching Schedule
ユーザー 👑 chro_96chro_96
提出日時 2023-03-11 18:28:01
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 298 ms / 4,000 ms
コード長 2,586 bytes
コンパイル時間 1,078 ms
コンパイル使用メモリ 33,672 KB
実行使用メモリ 6,572 KB
最終ジャッジ日時 2023-10-18 10:11:32
合計ジャッジ時間 7,506 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,864 KB
testcase_01 AC 3 ms
5,864 KB
testcase_02 AC 4 ms
5,864 KB
testcase_03 AC 4 ms
5,864 KB
testcase_04 AC 8 ms
6,044 KB
testcase_05 AC 58 ms
6,572 KB
testcase_06 AC 200 ms
6,308 KB
testcase_07 AC 216 ms
6,308 KB
testcase_08 AC 191 ms
6,308 KB
testcase_09 AC 296 ms
6,044 KB
testcase_10 AC 294 ms
6,044 KB
testcase_11 AC 298 ms
6,044 KB
testcase_12 AC 276 ms
6,044 KB
testcase_13 AC 245 ms
6,044 KB
testcase_14 AC 246 ms
6,044 KB
testcase_15 AC 245 ms
6,044 KB
testcase_16 AC 57 ms
6,044 KB
testcase_17 AC 53 ms
5,864 KB
testcase_18 AC 130 ms
6,308 KB
testcase_19 AC 227 ms
5,864 KB
testcase_20 AC 169 ms
5,888 KB
testcase_21 AC 81 ms
6,044 KB
testcase_22 AC 65 ms
6,044 KB
testcase_23 AC 14 ms
6,044 KB
testcase_24 AC 121 ms
6,044 KB
testcase_25 AC 15 ms
5,864 KB
testcase_26 AC 40 ms
6,044 KB
testcase_27 AC 135 ms
5,864 KB
testcase_28 AC 17 ms
5,864 KB
testcase_29 AC 158 ms
5,864 KB
testcase_30 AC 179 ms
6,308 KB
testcase_31 AC 176 ms
6,308 KB
testcase_32 AC 63 ms
5,864 KB
testcase_33 AC 45 ms
6,044 KB
testcase_34 AC 132 ms
6,044 KB
testcase_35 AC 170 ms
6,044 KB
testcase_36 AC 164 ms
6,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

int cmp_int_rev (const void *ap, const void *bp) {
  int a = *(int *)ap;
  int b = *(int *)bp;
  
  if (a < b) {
    return 1;
  }
  
  if (a > b) {
    return -1;
  }
  
  return 0;
}

long long power_mod (long long a, long long b, long long mod_num) {
  long long ans = 1LL;
  
  if (b > 0LL) {
    ans = power_mod(a, b/2LL, mod_num);
    ans = (ans * ans) % mod_num;
    if (b%2LL == 1LL) {
      ans = (ans * (a % mod_num)) % mod_num;
    }
  }
  
  return ans;
}

int main () {
  int m = 0;
  int n = 0;
  int a = 0;
  
  int res = 0;
  
  long long ans = 0LL;
  long long mod_num = 998244353LL;
  
  long long s[100001] = {};
  long long b[100001] = {};
  
  long long fact[100002] = {};
  long long invf[100002] = {};
  
  int c[100001][2] = {};
  int cnt = 0;
  
  res = scanf("%d", &m);
  res = scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    res = scanf("%d", &a);
    c[a][0]++;
  }
  
  fact[0] = 1LL;
  for (int i = 0; i < n+1; i++) {
    fact[i+1] = fact[i];
    fact[i+1] *= (long long) (i+1);
    fact[i+1] %= mod_num;
  }
  
  invf[n+1] = power_mod(fact[n+1], mod_num-2LL, mod_num);
  for (int i = n+1; i > 0; i--) {
    invf[i-1] = invf[i];
    invf[i-1] *= (long long)i;
    invf[i-1] %= mod_num;
  }
  
  qsort(c, m+1, sizeof(int)*2, cmp_int_rev);
  
  c[0][1] = 1;
  cnt = 1;
  for (int i = 1; i <= m; i++) {
    if (c[i-1][0] != c[i][0]) {
      c[cnt][0] = c[i][0];
      c[cnt][1] = 0;
      cnt++;
    }
    c[cnt-1][1]++;
  }
  
  for (int i = 1; i <= n; i++) {
    s[i] = 1LL;
  }
  
  for (int i = 0; i < cnt; i++) {
    for (int j = 0; j < c[i][0]; j++) {
      s[j] = 0LL;
    }
    for (int j = c[i][0]; j <= n; j++) {
      long long mul = fact[j];
      mul *= invf[j-c[i][0]];
      s[j] *= power_mod(mul, (long long)c[i][1], mod_num);
      s[j] %= mod_num;
    }
  }
  
  if (n%2 == 0) {
    b[1] = ((long long)(n/2))*(-1LL)+mod_num;
    b[1] %= mod_num;
  } else {
    b[1] = ((long long)(n/2))+1LL;
  }
  
  for (int i = 2; i <= n; i++) {
    b[i] = fact[n+1];
    b[i] *= invf[i];
    b[i] %= mod_num;
    b[i] *= invf[n-i+1];
    b[i] %= mod_num;
    b[i] += mod_num-b[i-1];
    b[i] *= (mod_num+1LL)/2LL;
    if (n%2 == 0) {
      long long sub = fact[n+1];
      sub *= invf[i];
      sub %= mod_num;
      sub *= invf[n-i+1];
      b[i] += mod_num-sub%mod_num;;
    }
    b[i] %= mod_num;
  }
  
  for (int i = 1; i <= n; i++) {
    if (i%2 == 1) {
      ans += (b[i]*s[i])%mod_num;
    } else {
      ans += mod_num-(b[i]*s[i])%mod_num;
    }
  }
  
  printf("%lld\n", ans%mod_num);
  return 0;
}
0