結果

問題 No.2229 Treasure Searching Rod (Hard)
ユーザー 👑 rin204rin204
提出日時 2023-03-06 00:33:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 208 ms / 2,000 ms
コード長 702 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 81,708 KB
実行使用メモリ 76,616 KB
最終ジャッジ日時 2023-10-18 05:03:05
合計ジャッジ時間 6,436 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,444 KB
testcase_01 AC 37 ms
53,444 KB
testcase_02 AC 38 ms
53,444 KB
testcase_03 AC 39 ms
53,444 KB
testcase_04 AC 38 ms
53,444 KB
testcase_05 AC 38 ms
53,444 KB
testcase_06 AC 38 ms
53,444 KB
testcase_07 AC 193 ms
76,184 KB
testcase_08 AC 199 ms
76,204 KB
testcase_09 AC 206 ms
76,280 KB
testcase_10 AC 193 ms
76,184 KB
testcase_11 AC 208 ms
76,616 KB
testcase_12 AC 131 ms
75,876 KB
testcase_13 AC 131 ms
75,876 KB
testcase_14 AC 130 ms
75,888 KB
testcase_15 AC 194 ms
76,196 KB
testcase_16 AC 202 ms
76,216 KB
testcase_17 AC 193 ms
76,204 KB
testcase_18 AC 198 ms
76,216 KB
testcase_19 AC 198 ms
76,232 KB
testcase_20 AC 195 ms
76,148 KB
testcase_21 AC 197 ms
76,220 KB
testcase_22 AC 196 ms
76,236 KB
testcase_23 AC 125 ms
75,908 KB
testcase_24 AC 137 ms
75,900 KB
testcase_25 AC 143 ms
76,064 KB
testcase_26 AC 111 ms
75,948 KB
testcase_27 AC 89 ms
75,896 KB
testcase_28 AC 169 ms
75,908 KB
testcase_29 AC 167 ms
75,952 KB
testcase_30 AC 93 ms
76,016 KB
testcase_31 AC 105 ms
76,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def leq_cnt(x, y, z):
    """
    i \\in [0, x), j \\in [0, y), i + j <= z を満たす (i, j) の個数を返す
    """
    if z < 0:
        return 0
    if z >= x + y - 2:
        return x * y

    l1 = z - x + 1
    l2 = z + 1
    if l1 >= 0:
        ret = l1 * x
        ret += x * (x + 1) // 2
    else:
        ret = (z + 1) * (z + 2) // 2
    if l2 >= y:
        ret -= (z - y + 2) * (z - y + 1) // 2
    return ret

MOD = 998244353
h, w, k = map(int, input().split())
ans = 0
for i in range(k):
    x, y, z = map(int, input().split())
    cnt = x
    cnt += leq_cnt(x - 1, y - 1, x - 2)
    cnt += leq_cnt(x - 1, w - y, x - 2)
    cnt %= MOD
    ans += cnt * z % MOD
    ans %= MOD
print(ans)
0