結果

問題 No.1310 量子アニーリング
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-16 10:42:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 1,139 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 132,728 KB
最終ジャッジ日時 2023-08-28 17:27:23
合計ジャッジ時間 3,961 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,276 KB
testcase_01 AC 66 ms
71,404 KB
testcase_02 AC 66 ms
71,460 KB
testcase_03 AC 67 ms
71,556 KB
testcase_04 AC 66 ms
71,468 KB
testcase_05 AC 72 ms
71,404 KB
testcase_06 AC 67 ms
71,404 KB
testcase_07 AC 67 ms
71,368 KB
testcase_08 AC 67 ms
71,516 KB
testcase_09 AC 67 ms
71,348 KB
testcase_10 AC 70 ms
71,504 KB
testcase_11 AC 75 ms
76,092 KB
testcase_12 AC 80 ms
76,384 KB
testcase_13 AC 99 ms
88,404 KB
testcase_14 AC 110 ms
95,720 KB
testcase_15 AC 119 ms
101,992 KB
testcase_16 AC 118 ms
101,668 KB
testcase_17 AC 142 ms
114,784 KB
testcase_18 AC 157 ms
132,728 KB
testcase_19 AC 113 ms
98,632 KB
testcase_20 AC 91 ms
83,692 KB
testcase_21 AC 85 ms
78,360 KB
testcase_22 AC 156 ms
132,516 KB
testcase_23 AC 101 ms
88,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main0(n):
  mod=998244353
  ans=0
  for i in range(1<<n):
    ary=[]
    for j in range(n):
      if (i>>j)&1:
        ary.append(1)
      else:
        ary.append(-1)
    tmp=0
    for j in range(n):
      tmp+=-ary[j]*ary[j-1]
    ans+=pow(2,abs(tmp))
    ans%=mod
  return ans
"""
正負切り替わるところの個数をxとするとE=n-2*x
xは偶数のみ取る。
場合数はcmb(n,x)
"""
def main1(n):
  mod=998244353
  def cmb(n,r,mod=mod):
    if (r<0 or r>n):
      return 0
    r=min(r,n-r)
    return (g1[n]*g2[r]*g2[n-r])%mod
  g1=[1,1] # g1[i]=i! % mod :階乗
  g2=[1,1] # g2[i]=(i!)^(-1) % mod :階乗の逆元
  inverse=[0,1]
  for i in range(2,n+1):
    g1.append((g1[-1]*i)%mod)
    inverse.append((-inverse[mod%i]*(mod//i))%mod)
    g2.append((g2[-1]*inverse[-1])%mod)
  ans=0
  p2=[1,2,4]
  for _ in range(n):p2.append(p2[-1]*2%mod)
  for x in range(0,n+1,2):
    # 正負が切り替わる所の個数
    # E=n-2*x
    e=n-2*x
    tmp=2*cmb(n,x)
    ans+=p2[abs(e)]*tmp%mod
    ans%=mod
  return ans

if __name__=='__main__':
  n=int(input())
  #ret0=main0(n)
  #print(ret0)
  ret1=main1(n)
  print(ret1)
0