結果

問題 No.2229 Treasure Searching Rod (Hard)
ユーザー chineristACchineristAC
提出日時 2023-02-24 23:12:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 220 ms / 2,000 ms
コード長 1,166 bytes
コンパイル時間 827 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 81,868 KB
最終ジャッジ日時 2023-10-11 06:51:47
合計ジャッジ時間 7,860 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
74,876 KB
testcase_01 AC 115 ms
74,460 KB
testcase_02 AC 117 ms
74,636 KB
testcase_03 AC 117 ms
74,584 KB
testcase_04 AC 117 ms
74,716 KB
testcase_05 AC 117 ms
74,648 KB
testcase_06 AC 116 ms
74,552 KB
testcase_07 AC 205 ms
81,416 KB
testcase_08 AC 212 ms
81,432 KB
testcase_09 AC 212 ms
81,380 KB
testcase_10 AC 207 ms
81,188 KB
testcase_11 AC 220 ms
81,868 KB
testcase_12 AC 175 ms
81,284 KB
testcase_13 AC 171 ms
81,120 KB
testcase_14 AC 170 ms
80,988 KB
testcase_15 AC 213 ms
81,296 KB
testcase_16 AC 214 ms
81,124 KB
testcase_17 AC 213 ms
81,052 KB
testcase_18 AC 214 ms
81,644 KB
testcase_19 AC 214 ms
81,460 KB
testcase_20 AC 213 ms
81,396 KB
testcase_21 AC 216 ms
81,592 KB
testcase_22 AC 211 ms
81,456 KB
testcase_23 AC 167 ms
81,044 KB
testcase_24 AC 176 ms
81,240 KB
testcase_25 AC 181 ms
81,104 KB
testcase_26 AC 166 ms
81,356 KB
testcase_27 AC 148 ms
81,296 KB
testcase_28 AC 194 ms
80,928 KB
testcase_29 AC 197 ms
81,336 KB
testcase_30 AC 151 ms
81,408 KB
testcase_31 AC 155 ms
80,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
    
0