結果

問題 No.2299 Antitypoglycemia
ユーザー FromBooskaFromBooska
提出日時 2023-10-21 11:30:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 247 ms / 2,000 ms
コード長 660 bytes
コンパイル時間 1,049 ms
コンパイル使用メモリ 81,456 KB
実行使用メモリ 89,368 KB
最終ジャッジ日時 2023-10-21 11:30:51
合計ジャッジ時間 5,695 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,320 KB
testcase_01 AC 39 ms
53,320 KB
testcase_02 AC 38 ms
53,320 KB
testcase_03 AC 176 ms
78,280 KB
testcase_04 AC 180 ms
80,392 KB
testcase_05 AC 124 ms
71,192 KB
testcase_06 AC 175 ms
78,288 KB
testcase_07 AC 73 ms
64,052 KB
testcase_08 AC 168 ms
78,136 KB
testcase_09 AC 181 ms
80,424 KB
testcase_10 AC 94 ms
66,800 KB
testcase_11 AC 98 ms
67,696 KB
testcase_12 AC 192 ms
80,592 KB
testcase_13 AC 237 ms
89,232 KB
testcase_14 AC 61 ms
62,072 KB
testcase_15 AC 59 ms
61,792 KB
testcase_16 AC 103 ms
68,696 KB
testcase_17 AC 78 ms
64,648 KB
testcase_18 AC 245 ms
89,368 KB
testcase_19 AC 246 ms
89,368 KB
testcase_20 AC 244 ms
89,368 KB
testcase_21 AC 247 ms
89,368 KB
testcase_22 AC 246 ms
89,368 KB
testcase_23 AC 38 ms
53,320 KB
testcase_24 AC 38 ms
53,320 KB
testcase_25 AC 38 ms
53,320 KB
testcase_26 AC 38 ms
53,320 KB
testcase_27 AC 38 ms
53,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 包除原理だな
# if A!=B, total - (N-1)!*2 + (N-2)!
# if A==B, (N-2)*(N-1)!

N, A, B = map(int, input().split())
mod = 998244353

# nCrメモ化パッケージ
factorial = [1] #0分
inverse = [1] #0分
for i in range(1, N+1):
    factorial.append(factorial[-1]*i%mod)
    inverse.append(pow(factorial[-1], mod-2, mod))
    
def nCr_fast(N, R, MOD):
    if N < R or R < 0:
        return 0
    elif R == 0 or R == N:
        return 1
    return factorial[N]*inverse[R]*inverse[N-R]%MOD

if A!=B:
    ans = factorial[N]
    ans -= factorial[N-1]*2
    ans += factorial[N-2]
    ans %= mod
elif A==B:
    ans = (N-2)*factorial[N-1]
    ans %= mod
print(ans)
0