結果

問題 No.2243 Coaching Schedule
ユーザー chro_96chro_96
提出日時 2023-03-11 18:28:01
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 287 ms / 4,000 ms
コード長 2,586 bytes
コンパイル時間 1,954 ms
コンパイル使用メモリ 33,592 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-18 06:40:30
合計ジャッジ時間 5,854 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 6 ms
6,940 KB
testcase_05 AC 52 ms
6,944 KB
testcase_06 AC 187 ms
6,940 KB
testcase_07 AC 208 ms
6,940 KB
testcase_08 AC 178 ms
6,944 KB
testcase_09 AC 280 ms
6,940 KB
testcase_10 AC 282 ms
6,940 KB
testcase_11 AC 287 ms
6,944 KB
testcase_12 AC 262 ms
6,940 KB
testcase_13 AC 227 ms
6,940 KB
testcase_14 AC 229 ms
6,940 KB
testcase_15 AC 227 ms
6,940 KB
testcase_16 AC 50 ms
6,944 KB
testcase_17 AC 46 ms
6,944 KB
testcase_18 AC 115 ms
6,944 KB
testcase_19 AC 209 ms
6,940 KB
testcase_20 AC 154 ms
6,940 KB
testcase_21 AC 74 ms
6,944 KB
testcase_22 AC 59 ms
6,944 KB
testcase_23 AC 12 ms
6,940 KB
testcase_24 AC 111 ms
6,940 KB
testcase_25 AC 13 ms
6,944 KB
testcase_26 AC 35 ms
6,940 KB
testcase_27 AC 124 ms
6,940 KB
testcase_28 AC 16 ms
6,944 KB
testcase_29 AC 146 ms
6,944 KB
testcase_30 AC 162 ms
6,944 KB
testcase_31 AC 161 ms
6,940 KB
testcase_32 AC 58 ms
6,944 KB
testcase_33 AC 42 ms
6,940 KB
testcase_34 AC 121 ms
6,940 KB
testcase_35 AC 156 ms
6,944 KB
testcase_36 AC 150 ms
6,940 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