結果

問題 No.2229 Treasure Searching Rod (Hard)
ユーザー AngrySadEight
提出日時 2022-12-09 00:50:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 511 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 82,312 KB
実行使用メモリ 76,768 KB
最終ジャッジ日時 2024-10-14 18:21:27
合計ジャッジ時間 8,092 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W, K = map(int, input().split())
ans = 0
mod = 998244353

def calc(x, y):
    ret = 0
    if x <= y:
        ret += x * (x + 1) // 2
    else:
        ret += (x * (x + 1) // 2 - (x - y) * (x - y + 1) // 2)

    if x <= W - y + 1:
        ret += x * (x + 1) // 2
    else:
        ret += (x * (x + 1) // 2 - (x - (W - y + 1)) * (x - (W - y + 1) + 1) // 2)
    ret -= x
    return ret

for i in range(K):
    x, y, v = map(int, input().split())
    C = calc(x, y) % mod
    ans = (ans + C * v) % mod
print(ans)
0