結果

問題 No.2520 L1 Explosion
ユーザー MasKoaTSMasKoaTS
提出日時 2023-03-28 22:46:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 406 ms / 2,000 ms
コード長 1,155 bytes
コンパイル時間 608 ms
コンパイル使用メモリ 87,240 KB
実行使用メモリ 149,612 KB
最終ジャッジ日時 2023-10-04 12:03:25
合計ジャッジ時間 7,883 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,268 KB
testcase_01 AC 77 ms
71,568 KB
testcase_02 AC 71 ms
71,268 KB
testcase_03 AC 71 ms
71,264 KB
testcase_04 AC 78 ms
71,316 KB
testcase_05 AC 74 ms
71,408 KB
testcase_06 AC 383 ms
149,028 KB
testcase_07 AC 184 ms
96,472 KB
testcase_08 AC 380 ms
149,612 KB
testcase_09 AC 406 ms
149,424 KB
testcase_10 AC 382 ms
149,368 KB
testcase_11 AC 383 ms
149,216 KB
testcase_12 AC 398 ms
149,524 KB
testcase_13 AC 380 ms
149,288 KB
testcase_14 AC 379 ms
149,508 KB
testcase_15 AC 94 ms
76,368 KB
testcase_16 AC 316 ms
128,784 KB
testcase_17 AC 221 ms
109,296 KB
testcase_18 AC 225 ms
108,940 KB
testcase_19 AC 207 ms
105,260 KB
testcase_20 AC 86 ms
76,344 KB
testcase_21 AC 303 ms
125,148 KB
testcase_22 AC 106 ms
76,252 KB
testcase_23 AC 98 ms
76,528 KB
testcase_24 AC 269 ms
118,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
MOD = 998244353

def solve():
	n, m = map(int, input().split())

	X1 = [];	X2 = [];	Xst = set([])
	Y1 = [];	Y2 = [];	Yst = set([])
	for x, y, h in (map(int, input().split()) for _ in [0] * n):
		d = m - h
		x1, y1 = (x - d) - y, (x - d) + y
		x2, y2 = (x + d) - y, (x + d) + y
		X1.append(x1);	X2.append(x2);	Xst |= set([x1, x2])	
		Y1.append(y1);	Y2.append(y2);	Yst |= set([y1, y2])

	X = sorted(Xst);	Y = sorted(Yst)
	hX = {};	hY = {}
	for i, (x, y) in enumerate(zip(X, Y)):
		hX[x] = hY[y] = i
	h, w = len(hX), len(hY)

	dp = [[0] * w for _ in [0] * h]
	for x1, y1, x2, y2 in zip(X1, Y1, X2, Y2):
		dp[hX[x1]][hY[y1]] += 1
		dp[hX[x1]][hY[y2]] -= 1
		dp[hX[x2]][hY[y1]] -= 1
		dp[hX[x2]][hY[y2]] += 1
	for i in range(h):
		for j in range(1, w):
			dp[i][j] += dp[i][j - 1]
	for i in range(1, h):
		for j in range(w):
			dp[i][j] += dp[i - 1][j]

	ans = [0] * (n + 1)
	for i in range(h - 1):
		for j in range(w - 1):
			ans[dp[i][j]] += ((X[i + 1] - X[i]) % MOD) * ((Y[j + 1] - Y[j]) % MOD) % MOD
			ans[dp[i][j]] %= MOD
	div2 = pow(2, MOD - 2, MOD)
	for i in range(1, n + 1):
		print(ans[i] * div2 % MOD)

solve()
0