結果

問題 No.2048 L(I+D)S
ユーザー JashinchanJashinchan
提出日時 2022-08-24 10:17:24
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 1,176 bytes
コンパイル時間 812 ms
コンパイル使用メモリ 31,616 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 01:23:46
合計ジャッジ時間 2,718 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
5,248 KB
testcase_01 AC 4 ms
5,376 KB
testcase_02 AC 7 ms
5,376 KB
testcase_03 AC 5 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 117 ms
5,376 KB
testcase_09 AC 48 ms
5,376 KB
testcase_10 AC 40 ms
5,376 KB
testcase_11 AC 142 ms
5,376 KB
testcase_12 AC 69 ms
5,376 KB
testcase_13 AC 45 ms
5,376 KB
testcase_14 AC 53 ms
5,376 KB
testcase_15 AC 23 ms
5,376 KB
testcase_16 AC 142 ms
5,376 KB
testcase_17 AC 147 ms
5,376 KB
testcase_18 AC 149 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const long long mod = 998244353LL;
long long fact_table[200000];
long long invfact_table[200000];
long long pow_mod(long long a, long long k, long long m)
{
    long long ret = 1LL;
    while (k > 0)
    {
        if (k & 1)
            ret = (long long)((__int128_t)ret * a % m);
        a = (long long)((__int128_t)a * a % m);
        k >>= 1;
    }
    return ret;
}
void init_table(void)
{
    fact_table[0] = 1;
    for (int i = 1; i < 200000; ++i)
        fact_table[i] = fact_table[i - 1] * i % mod;
    invfact_table[199999] = pow_mod(fact_table[199999], mod - 2, mod);
    for (int i = 199998; i >= 0; --i)
        invfact_table[i] = invfact_table[i + 1] * (i + 1) % mod;
}

int main(void)
{
    init_table();

    long long N;
    scanf("%lld", &N);

    long long ans = 0LL;
    long long e = N * fact_table[N - 2] % mod;
    for (long long i = 2; i < N - 1; ++i)
    {
        long long s = invfact_table[i - 2] * invfact_table[N - i - 2] % mod;
        s = s * pow_mod(i, mod - 2, mod) % mod * pow_mod(N - i, mod - 2, mod) % mod;
        ans = (ans + (s * e % mod) * (s * e % mod) % mod) % mod;
    }
    printf("%ld\n", ans);
    return 0;
}
0