結果
| 問題 |
No.2229 Treasure Searching Rod (Hard)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-02-24 23:12:00 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 152 ms / 2,000 ms |
| コード長 | 1,166 bytes |
| コンパイル時間 | 225 ms |
| コンパイル使用メモリ | 82,236 KB |
| 実行使用メモリ | 77,652 KB |
| 最終ジャッジ日時 | 2024-09-13 06:03:50 |
| 合計ジャッジ時間 | 5,172 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log
input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())
mod = 998244353
H,W,K = mi()
tre = []
res = 0
for _ in range(K):
x,y,v = mi()
x,y = x-1,y-1
"""
1 <= i <= H
1 <= j <= W
i+j <= x+y
i-j <= x-y
をみたすijの数え上げ
for i in range(H):
j_min = max(0,i-(x-y))
j_max= min(W-1,x+y-i)
"""
tmp = 0
i_upper = min(x+1,H,W+x-y,x+y+1)
if i_upper <= 0:
continue
tmp = i_upper
c = x+y-(W-1)
if 0 <= c <= i_upper:
tmp += c * (W-1)
tmp += (x+y) * (i_upper-c)
tmp -= i_upper*(i_upper-1)//2 - c*(c-1)//2
elif c < 0:
tmp += (x+y) * i_upper
tmp -= i_upper*(i_upper-1)//2
else:
tmp += i_upper * (W-1)
if max(0,x-y) < i_upper:
tmp += (x-y) * (i_upper-max(0,x-y))
tmp -= i_upper*(i_upper-1)//2 - max(0,x-y)*(max(0,x-y)-1)//2
res += v * tmp % mod
print(res % mod)