結果

問題 No.1832 NAND Reversible
ユーザー googol_S0googol_S0
提出日時 2022-02-04 22:02:00
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 842 bytes
コンパイル時間 462 ms
コンパイル使用メモリ 86,988 KB
実行使用メモリ 110,152 KB
最終ジャッジ日時 2023-09-02 04:51:46
合計ジャッジ時間 5,289 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
99,316 KB
testcase_01 AC 109 ms
99,380 KB
testcase_02 AC 106 ms
99,264 KB
testcase_03 AC 177 ms
100,880 KB
testcase_04 AC 105 ms
99,516 KB
testcase_05 AC 106 ms
99,356 KB
testcase_06 AC 126 ms
99,944 KB
testcase_07 AC 151 ms
104,020 KB
testcase_08 WA -
testcase_09 AC 109 ms
99,508 KB
testcase_10 AC 130 ms
100,292 KB
testcase_11 AC 108 ms
99,464 KB
testcase_12 AC 106 ms
99,576 KB
testcase_13 AC 106 ms
99,388 KB
testcase_14 AC 110 ms
99,356 KB
testcase_15 AC 154 ms
105,856 KB
testcase_16 AC 158 ms
108,904 KB
testcase_17 AC 145 ms
100,652 KB
testcase_18 AC 151 ms
100,752 KB
testcase_19 AC 149 ms
100,724 KB
testcase_20 AC 108 ms
99,516 KB
testcase_21 WA -
testcase_22 AC 125 ms
99,784 KB
testcase_23 AC 106 ms
99,364 KB
testcase_24 AC 106 ms
99,380 KB
testcase_25 AC 161 ms
110,152 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()
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