結果

問題 No.1310 量子アニーリング
ユーザー FromBooskaFromBooska
提出日時 2023-03-21 11:38:57
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 952 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 81,752 KB
実行使用メモリ 101,348 KB
最終ジャッジ日時 2023-10-18 18:23:13
合計ジャッジ時間 4,485 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,452 KB
testcase_01 AC 36 ms
53,480 KB
testcase_02 AC 36 ms
53,480 KB
testcase_03 AC 36 ms
53,480 KB
testcase_04 WA -
testcase_05 AC 36 ms
53,480 KB
testcase_06 WA -
testcase_07 AC 37 ms
53,480 KB
testcase_08 AC 40 ms
53,480 KB
testcase_09 AC 36 ms
53,480 KB
testcase_10 WA -
testcase_11 AC 45 ms
61,996 KB
testcase_12 AC 54 ms
64,320 KB
testcase_13 AC 114 ms
75,176 KB
testcase_14 AC 144 ms
79,016 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 235 ms
93,656 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 98 ms
70,448 KB
testcase_21 AC 73 ms
67,660 KB
testcase_22 AC 294 ms
101,264 KB
testcase_23 AC 115 ms
75,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 仕組みはわかったが愚直な計算では間に合わない気がする

N = int(input())
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

ans = 0
if N%2 == 1:
    temp = N//2
    for i in range(1, N+1, 2):
        calc = nCr_fast(N, temp, mod)*2
        temp -= 1
        ans += calc*pow(2, i, mod)
        ans %= mod
        #print('i', i, 'calc', calc, calc*pow(2, i, mod))
elif N%2 == 0:
    temp = N//2
    for i in range(0, N+1, 2):
        calc = nCr_fast(N, temp, mod)*2
        temp -= 1
        ans += calc*pow(2, i, mod)
        ans %= mod
        #print('i', i, 'calc', calc, calc*pow(2, i, mod))
print(ans)
0