結果

問題 No.1832 NAND Reversible
ユーザー googol_S0googol_S0
提出日時 2022-02-04 22:03:19
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 885 bytes
コンパイル時間 1,092 ms
コンパイル使用メモリ 86,880 KB
実行使用メモリ 110,116 KB
最終ジャッジ日時 2023-09-02 04:53:29
合計ジャッジ時間 5,402 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
99,272 KB
testcase_01 AC 112 ms
99,480 KB
testcase_02 AC 112 ms
99,420 KB
testcase_03 AC 153 ms
100,936 KB
testcase_04 AC 115 ms
99,400 KB
testcase_05 AC 113 ms
99,332 KB
testcase_06 AC 135 ms
99,768 KB
testcase_07 AC 159 ms
103,944 KB
testcase_08 AC 112 ms
99,336 KB
testcase_09 AC 114 ms
99,408 KB
testcase_10 AC 142 ms
100,412 KB
testcase_11 AC 115 ms
99,404 KB
testcase_12 AC 116 ms
99,304 KB
testcase_13 AC 116 ms
99,248 KB
testcase_14 AC 115 ms
99,188 KB
testcase_15 AC 162 ms
106,032 KB
testcase_16 AC 168 ms
108,720 KB
testcase_17 AC 153 ms
100,668 KB
testcase_18 AC 157 ms
100,696 KB
testcase_19 AC 156 ms
100,612 KB
testcase_20 AC 113 ms
99,532 KB
testcase_21 AC 114 ms
99,308 KB
testcase_22 AC 131 ms
99,768 KB
testcase_23 AC 113 ms
99,424 KB
testcase_24 AC 112 ms
99,256 KB
testcase_25 AC 171 ms
110,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=998244353
def cmb(n,r):
  if r<0 or r>n:
    return 0
  return ((g1[n]*g2[r]%mod)*g2[n-r])%mod
 
N=1000000
g1=[1]*(N+3)
for i in range(2,N+3):
  g1[i]=g1[i-1]*i%mod
g2=[0]*len(g1)
g2[-1]=pow(g1[-1],mod-2,mod)
for i in range(N+1,-1,-1):
  g2[i]=g2[i+1]*(i+1)%mod
inv=[0]*(N+3)
for i in range(1,N+3):
  inv[i]=g2[i]*g1[i-1]%mod
N,K=map(int,input().split())
if K==0:
  print(1)
  exit()
if K==1:
  if N&1:
    print(N-2)
  else:
    print(2)
  exit()
if N==K:
  print(1)
  exit()
if K==2:
  N>>=1
  print(N*N%mod)
  exit()
A,B=0,0
x,y=1,2
for i in range(2,N+1):
  if i&1:
    x+=y
    if x>=mod:
      x-=mod
    y+=1
  A=(A+x*cmb(N-2-i,K-3))%mod
for i in range(3,K+1):
  A=(A+cmb(N-1-i,K-i))%mod
x,y=1,2
N-=2
for i in range(2,N+1):
  if i&1:
    x+=y
    if x>=mod:
      x-=mod
    y+=1
  B=(B+x*cmb(N-2-i,K-3))%mod
for i in range(3,K+1):
  B=(B+cmb(N-1-i,K-i))%mod
print((A+B)%mod)
0