結果

問題 No.2406 Difference of Coordinate Squared
ユーザー とりゐとりゐ
提出日時 2023-08-04 22:20:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,637 bytes
コンパイル時間 524 ms
コンパイル使用メモリ 82,580 KB
実行使用メモリ 218,800 KB
最終ジャッジ日時 2024-04-22 20:37:48
合計ジャッジ時間 5,426 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
62,080 KB
testcase_01 AC 84 ms
112,640 KB
testcase_02 AC 91 ms
115,584 KB
testcase_03 WA -
testcase_04 AC 89 ms
116,096 KB
testcase_05 AC 55 ms
65,468 KB
testcase_06 AC 57 ms
82,816 KB
testcase_07 AC 58 ms
78,080 KB
testcase_08 AC 45 ms
62,592 KB
testcase_09 AC 70 ms
97,408 KB
testcase_10 AC 76 ms
108,928 KB
testcase_11 AC 55 ms
62,336 KB
testcase_12 AC 65 ms
62,208 KB
testcase_13 AC 75 ms
103,680 KB
testcase_14 AC 79 ms
106,112 KB
testcase_15 AC 75 ms
111,104 KB
testcase_16 AC 64 ms
90,368 KB
testcase_17 AC 40 ms
62,080 KB
testcase_18 WA -
testcase_19 AC 52 ms
62,720 KB
testcase_20 AC 69 ms
108,800 KB
testcase_21 AC 65 ms
87,296 KB
testcase_22 WA -
testcase_23 AC 75 ms
111,616 KB
testcase_24 AC 52 ms
70,784 KB
testcase_25 WA -
testcase_26 AC 63 ms
61,952 KB
testcase_27 WA -
testcase_28 AC 43 ms
62,464 KB
testcase_29 AC 44 ms
62,080 KB
testcase_30 AC 45 ms
62,208 KB
testcase_31 AC 42 ms
62,080 KB
testcase_32 AC 42 ms
61,824 KB
testcase_33 AC 41 ms
61,952 KB
testcase_34 AC 42 ms
62,080 KB
testcase_35 AC 41 ms
62,208 KB
testcase_36 AC 41 ms
62,080 KB
testcase_37 AC 42 ms
62,080 KB
testcase_38 AC 42 ms
61,824 KB
testcase_39 WA -
testcase_40 AC 42 ms
61,952 KB
testcase_41 AC 41 ms
61,952 KB
testcase_42 WA -
testcase_43 AC 41 ms
62,080 KB
testcase_44 AC 40 ms
62,080 KB
testcase_45 AC 41 ms
61,952 KB
testcase_46 AC 40 ms
62,344 KB
testcase_47 AC 42 ms
62,208 KB
testcase_48 WA -
testcase_49 AC 40 ms
62,080 KB
testcase_50 AC 40 ms
61,952 KB
testcase_51 AC 41 ms
62,336 KB
testcase_52 AC 41 ms
62,080 KB
testcase_53 AC 42 ms
62,080 KB
testcase_54 AC 40 ms
62,208 KB
testcase_55 AC 40 ms
61,824 KB
testcase_56 AC 40 ms
62,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
input=lambda :stdin.readline()[:-1]

mod=998244353
n,m=map(int,input().split())
def divisors(n):
  lower,upper=[],[]
  i=1
  while i*i<=n:
    if n%i==0:
      lower.append(i)
      if i!=n//i:
        upper.append(n//i)
    i+=1
  return lower+upper[::-1]

xy=[]
if m==0:
  for i in range(-n,n+1):
    xy.append((i,i))
else:
  for d in divisors(abs(m)):
    if (d+m//d)%2==0:
      # x + y = d, x - y = m // d
      x=(d+(m//d))//2
      y=(d-(m//d))//2
      if abs(x)<=n and abs(y)<=n:
        xy.append((x,y))
        xy.append((-x,-y))

mod=998244353
table_size=2*10**5

fac=[1]*(table_size+1)
finv=[1]*(table_size+1)

for i in range(2,table_size+1):
  fac[i]=fac[i-1]*i%mod
finv[table_size]=pow(fac[table_size],mod-2,mod)
for i in range(table_size-1,-1,-1):
  finv[i]=finv[i+1]*(i+1)%mod

def rebuild(n):
  global table_size,fac,finv
  fac+=[0]*(n-table_size)
  fac+=[0]*(n-table_size)
  finv+=[0]*(n-table_size)
  for i in range(table_size+1,n+1):
    fac[i]=fac[i-1]*i%mod
  finv[n]=inv(fac[n])
  for i in range(n-1,table_size,-1):
    finv[i]=finv[i+1]*(i+1)%mod
  table_size=n

def binom(n,k):
  if n<0 or k<0:
    return 0
  if k>n:
    return 0
  if n>table_size:
    rebuild(n+10**4)
  return (fac[n]*finv[k]%mod)*finv[n-k]%mod

def fpow(x,k):
  res=1
  while k:
    if k&1:
      res=res*x%mod
    x=x*x%mod
    k>>=1
  return res

def inv(a):
  if a<table_size:
    return fac[a-1]*finv[a]%mod
  return fpow(a,mod-2)

ans=0
for x,y in xy:
  s=(x+y)
  t=(x-y)
  if (s+n)%2==0 and (t+n)%2==0:
    a=(s+n)//2
    b=(t+n)//2
    ans+=binom(n,a)*binom(n,b)
    ans%=mod

ans*=inv(fpow(4,n))
print(ans%mod)
0