結果

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

ソースコード

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)
rev6=pow(6,mod-2,mod)
def f1(x):

    return (x*(x+1)%mod*rev2)%mod
def f2(x):

    return (x*(x+1)%mod*(2*x+1)*rev6)%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