結果

問題 No.1546 [Cherry 2nd Tune D] 思ったよりも易しくない
ユーザー taiga0629kyopro
提出日時 2021-06-11 22:37:00
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 557 bytes
コンパイル時間 378 ms
コンパイル使用メモリ 82,336 KB
実行使用メモリ 99,352 KB
最終ジャッジ日時 2024-12-15 00:59:41
合計ジャッジ時間 15,073 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 WA * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
nod=[]
mod=998244353
sumt=0
for _ in range(n):
    t,v=map(int,input().split())
    sumt+=t
    sumt%=mod
    nod.append((t,v))
s=1
ans=0
rev2=pow(2,mod-2,mod)
def f1(x):
    
    return (x*(x+1)//2)%mod
def f2(x):
   
    return (x*(x+1)%mod*(2*x+1)//6)%mod
def f3(x):
  
    return (f1(x)**2)%mod
n=sumt%mod
for t,v in nod:
    g=s+t-1
    g%=mod
    subans=0
    subans+=n*(f2(g)-f2(s-1))
    subans+=-(f3(g)-f3(s-1))
    subans+=(n+1)*(f1(g)-f1(s-1))
    subans*=v*rev2
    ans+=subans
    ans%=mod
    s+=t
    s%=mod


print(ans%mod)


0