結果
| 問題 |
No.2229 Treasure Searching Rod (Hard)
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-31 17:51:41 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 207 ms / 2,000 ms |
| コード長 | 1,451 bytes |
| コンパイル時間 | 264 ms |
| コンパイル使用メモリ | 82,236 KB |
| 実行使用メモリ | 141,488 KB |
| 最終ジャッジ日時 | 2025-03-31 17:52:35 |
| 合計ジャッジ時間 | 7,251 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
MOD = 998244353
def main():
import sys
input = sys.stdin.read
data = input().split()
idx = 0
H = int(data[idx]); idx +=1
W = int(data[idx]); idx +=1
K = int(data[idx]); idx +=1
total = 0
for _ in range(K):
x = int(data[idx]); idx +=1
y = int(data[idx]); idx +=1
v = int(data[idx]); idx +=1
s = x + y
t = x - y
res = 0
# Case 1-1
a = max(x - y + 1, x + y - W, 1)
b = min(x, H, s - 1)
if a <= b:
n = b - a + 1
A = 2 * x - 2 * a + 1
B = 2 * x - 2 * b + 1
res += n * (A + B) // 2
# Case 1-2
a = max(x - y + 1, 1)
b = min(x + y - W - 1, x, H, s - 1)
if a <= b:
first = W + t + 1 - a
last = W + t + 1 - b
term = (first + last) * (b - a + 1) // 2
res += term
# Case 2-1
a = max(x + y - W, 1)
b = min(x - y, x + y - 1, H)
if a <= b:
first = s - a
last = s - b
term = (first + last) * (b - a + 1) // 2
res += term
# Case 2-2
a = 1
b = min(x + y - W - 1, x - y, H)
if a <= b:
res += W * (b - a + 1)
res %= MOD
total = (total + res * v) % MOD
print(total % MOD)
if __name__ == "__main__":
main()
lam6er