結果

問題 No.2206 Popcount Sum 2
ユーザー とりゐとりゐ
提出日時 2023-01-17 02:53:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,751 ms / 4,000 ms
コード長 843 bytes
コンパイル時間 516 ms
コンパイル使用メモリ 86,728 KB
実行使用メモリ 461,588 KB
最終ジャッジ日時 2023-09-15 11:00:34
合計ジャッジ時間 31,575 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,751 ms
459,584 KB
testcase_01 AC 890 ms
459,856 KB
testcase_02 AC 907 ms
459,912 KB
testcase_03 AC 907 ms
459,956 KB
testcase_04 AC 900 ms
460,000 KB
testcase_05 AC 1,523 ms
461,212 KB
testcase_06 AC 1,535 ms
461,104 KB
testcase_07 AC 1,533 ms
461,588 KB
testcase_08 AC 1,525 ms
460,944 KB
testcase_09 AC 1,523 ms
460,856 KB
testcase_10 AC 1,502 ms
460,984 KB
testcase_11 AC 1,505 ms
461,052 KB
testcase_12 AC 1,518 ms
460,884 KB
testcase_13 AC 1,461 ms
460,888 KB
testcase_14 AC 1,608 ms
460,892 KB
testcase_15 AC 1,488 ms
460,908 KB
testcase_16 AC 1,495 ms
460,928 KB
testcase_17 AC 1,492 ms
461,124 KB
testcase_18 AC 1,506 ms
461,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

mod=998244353
M=(10**5)*3+1 
fac=[1]*M
ninv=[1]*M
finv=[1]*M
for i in range(2,M):
  fac[i]=fac[i-1]*i%mod
  ninv[i]=(-(mod//i)*ninv[mod%i])%mod
  finv[i]=finv[i-1]*ninv[i]%mod

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

N=2*10**5+10
B=450

memo=[]
for i in range(B):
  a=[0]*(B*i+1)
  res=0
  for j in range(B*i+1):
    res+=binom(B*i,j)
    res%=mod
    a[j]=res
  memo.append(a)

inv2=pow(2,mod-2,mod)
pow2=[1]
for _ in range(M):
  pow2.append(pow2[-1]*2%mod)

T=int(input())
ans=[0]*T
for i in range(T):
  n,m=map(lambda x:int(x)-1,input().split())
  n0=(n+B-1)//B*B
  res=memo[n0//B][m]
  while n0>n:
    res=inv2*(res+binom(n0-1,m))
    res%=mod
    n0-=1
  ans[i]=res*(pow2[n+1]-1)%mod

print(*ans,sep='\n')
0