結果

問題 No.2754 Cumulate and Drop
ユーザー 👑 chro_96chro_96
提出日時 2024-05-10 21:58:40
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,226 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 31,360 KB
実行使用メモリ 9,676 KB
最終ジャッジ日時 2024-05-10 21:58:44
合計ジャッジ時間 1,555 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,544 KB
testcase_01 AC 3 ms
9,512 KB
testcase_02 AC 3 ms
9,648 KB
testcase_03 AC 3 ms
9,520 KB
testcase_04 AC 3 ms
9,600 KB
testcase_05 AC 3 ms
9,600 KB
testcase_06 AC 3 ms
9,520 KB
testcase_07 AC 3 ms
9,676 KB
testcase_08 AC 9 ms
9,468 KB
testcase_09 AC 23 ms
9,644 KB
testcase_10 AC 29 ms
9,540 KB
testcase_11 AC 21 ms
9,468 KB
testcase_12 AC 31 ms
9,644 KB
testcase_13 AC 28 ms
9,472 KB
testcase_14 AC 30 ms
9,536 KB
testcase_15 AC 19 ms
9,544 KB
testcase_16 AC 9 ms
9,644 KB
testcase_17 AC 32 ms
9,484 KB
testcase_18 AC 32 ms
9,580 KB
testcase_19 AC 31 ms
9,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

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 > 0LL) {
      ans = (ans * (a % mod_num)) % mod_num;
    }
  }
  
  return ans;
}

int main () {
  int n = 0;
  long long a[200000] = {};
  
  int res = 0;
  
  long long ans = 0LL;
  long long mod_num = 998244353LL;
  
  long long fact[400001] = {};
  long long invf[400001] = {};
  
  res = scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    res = scanf("%lld", a+i);
  }
  
  fact[0] = 1LL;
  for (int i = 0; i < 2*n; i++) {
    fact[i+1] = (fact[i]*((long long)i+1))%mod_num;
  }
  
  invf[2*n] = power_mod(fact[2*n], mod_num-2LL, mod_num);
  for (int i = 2*n; i > 0; i--) {
    invf[i-1] = (invf[i]*((long long)i))%mod_num;
  }
  
  for (int i = 0; i < n; i++) {
    long long tmp = (fact[2*n-2-i]*invf[n-i-1])%mod_num;
    tmp *= invf[n-1];
    tmp %= mod_num;
    if (n-i > 1) {
      long long tmp2 = (fact[2*n-2-i]*invf[n-i-2])%mod_num;
      tmp += mod_num-(tmp2*invf[n])%mod_num;
      tmp %= mod_num;
    }
    ans += a[i]*tmp;
    ans %= mod_num;
  }
  
  printf("%lld\n", ans);
  return 0;
}
0