結果

問題 No.1310 量子アニーリング
ユーザー wolgnikwolgnik
提出日時 2020-12-07 21:50:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 326 ms / 2,000 ms
コード長 1,124 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 103,248 KB
最終ジャッジ日時 2023-10-17 16:40:40
合計ジャッジ時間 3,552 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,628 KB
testcase_01 AC 39 ms
55,628 KB
testcase_02 AC 40 ms
55,628 KB
testcase_03 AC 40 ms
55,628 KB
testcase_04 AC 41 ms
55,628 KB
testcase_05 AC 44 ms
55,628 KB
testcase_06 AC 41 ms
55,628 KB
testcase_07 AC 44 ms
55,628 KB
testcase_08 AC 44 ms
55,628 KB
testcase_09 AC 44 ms
55,628 KB
testcase_10 AC 45 ms
55,628 KB
testcase_11 AC 50 ms
62,416 KB
testcase_12 AC 54 ms
66,540 KB
testcase_13 AC 83 ms
74,152 KB
testcase_14 AC 96 ms
78,360 KB
testcase_15 AC 195 ms
91,632 KB
testcase_16 AC 203 ms
90,840 KB
testcase_17 AC 138 ms
90,000 KB
testcase_18 AC 326 ms
103,248 KB
testcase_19 AC 183 ms
89,784 KB
testcase_20 AC 72 ms
71,208 KB
testcase_21 AC 62 ms
68,180 KB
testcase_22 AC 163 ms
94,096 KB
testcase_23 AC 82 ms
74,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import Counter
input = sys.stdin.readline
N = int(input())
mod = 998244353
res = 0

class Factorial:
  def __init__(self, n, mod):
    self.mod = mod
    self.f = [1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i = [pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i): return self.f[i]
  def ifactorial(self, i): return self.i[i]
  def combi(self, n, k): return self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod
  def permi(self, n, k): return self.f[n] * self.i[n - k] % self.mod

f = Factorial(N, mod)
if N % 2:
  for i in range(N + 1):
    res += f.combi(N, i) * pow(2, abs(N - 2 * i), mod)
    res %= mod
else:
  for i in range(N + 1):
    if i % 2:
      pw = pow(N, mod - 2, mod)
      l = f.combi(N, i) * pw * (N - i) % mod
      r = f.combi(N, i) * pw * i % mod
      res += pow(2, abs(N - 2 * i - 2), mod) * l + pow(2, abs(N - 2 * i + 2), mod) * r
    else: res += f.combi(N, i) * pow(2, abs(N - 2 * i), mod)
    res %= mod

print(res)
0