結果

問題 No.2225 Treasure Searching Rod (Easy)
ユーザー 👑 rin204rin204
提出日時 2023-03-06 00:34:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 702 bytes
コンパイル時間 1,050 ms
コンパイル使用メモリ 81,716 KB
実行使用メモリ 75,928 KB
最終ジャッジ日時 2023-10-18 05:03:17
合計ジャッジ時間 2,644 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,480 KB
testcase_01 AC 40 ms
53,480 KB
testcase_02 AC 39 ms
53,480 KB
testcase_03 AC 38 ms
53,480 KB
testcase_04 AC 38 ms
53,480 KB
testcase_05 AC 38 ms
53,480 KB
testcase_06 AC 39 ms
53,480 KB
testcase_07 AC 84 ms
75,924 KB
testcase_08 AC 82 ms
75,924 KB
testcase_09 AC 82 ms
75,924 KB
testcase_10 AC 38 ms
53,480 KB
testcase_11 AC 38 ms
53,480 KB
testcase_12 AC 82 ms
75,928 KB
testcase_13 AC 83 ms
75,924 KB
testcase_14 AC 82 ms
75,928 KB
testcase_15 AC 38 ms
53,480 KB
testcase_16 AC 38 ms
53,480 KB
testcase_17 AC 39 ms
53,480 KB
testcase_18 AC 38 ms
53,480 KB
testcase_19 AC 38 ms
53,480 KB
testcase_20 AC 39 ms
53,480 KB
testcase_21 AC 51 ms
57,576 KB
testcase_22 AC 39 ms
53,480 KB
testcase_23 AC 53 ms
63,116 KB
testcase_24 AC 40 ms
53,480 KB
testcase_25 AC 42 ms
55,528 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