結果

問題 No.2229 Treasure Searching Rod (Hard)
ユーザー tamato
提出日時 2023-02-24 21:50:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 583 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 81,524 KB
実行使用メモリ 76,068 KB
最終ジャッジ日時 2024-09-13 05:22:14
合計ジャッジ時間 4,498 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353


def main():
    import sys
    input = sys.stdin.readline

    def f(h):
        h += 1
        return h * (h + 1) // 2

    H, W, K = map(int, input().split())
    ans = 0
    for _ in range(K):
        h, w, v = map(int, input().split())
        h -= 1
        w -= 1
        tmp = ((h + 1) * (h + 1)) % mod
        h1 = h - w - 1
        if h1 >= 0:
            tmp = (tmp - f(h1)) % mod
        h2 = h - (W - w)
        if h2 >= 0:
            tmp = (tmp - f(h2)) % mod
        ans = (ans + tmp * v) % mod
    print(ans)


if __name__ == '__main__':
    main()
0