結果

問題 No.2229 Treasure Searching Rod (Hard)
ユーザー lloyzlloyz
提出日時 2024-01-02 14:30:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 437 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 82,368 KB
実行使用メモリ 77,012 KB
最終ジャッジ日時 2024-09-27 17:46:08
合計ジャッジ時間 7,504 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w, k = map(int, input().split())
mod = 998244353
ans = 0
inv2 = pow(2, mod - 2, mod)
for _ in range(k):
    x, y, v = map(int, input().split())
    cnt = pow(x, 2, mod)
    if y < x:
        d = x - y
        cnt -= d * (d + 1) % mod * inv2 % mod
        cnt %= mod
    if (w - y) < x - 1:
        d = x - (w - y) - 1
        cnt -= d * (d + 1) % mod * inv2 % mod
        cnt %= mod
    ans += v * cnt % mod
    ans %= mod
print(ans)
0