結果

問題 No.1997 X Lighting
ユーザー MasKoaTSMasKoaTS
提出日時 2022-03-31 13:55:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 335 ms / 2,000 ms
コード長 852 bytes
コンパイル時間 553 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 104,004 KB
最終ジャッジ日時 2024-04-28 12:00:40
合計ジャッジ時間 7,057 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,632 KB
testcase_01 AC 40 ms
53,008 KB
testcase_02 AC 41 ms
52,688 KB
testcase_03 AC 42 ms
52,620 KB
testcase_04 AC 41 ms
53,112 KB
testcase_05 AC 66 ms
70,024 KB
testcase_06 AC 82 ms
75,972 KB
testcase_07 AC 43 ms
54,340 KB
testcase_08 AC 60 ms
68,392 KB
testcase_09 AC 62 ms
68,036 KB
testcase_10 AC 42 ms
53,376 KB
testcase_11 AC 52 ms
60,340 KB
testcase_12 AC 42 ms
52,760 KB
testcase_13 AC 93 ms
76,164 KB
testcase_14 AC 261 ms
103,764 KB
testcase_15 AC 155 ms
81,048 KB
testcase_16 AC 180 ms
84,664 KB
testcase_17 AC 309 ms
95,312 KB
testcase_18 AC 216 ms
91,268 KB
testcase_19 AC 331 ms
102,680 KB
testcase_20 AC 332 ms
101,220 KB
testcase_21 AC 334 ms
101,212 KB
testcase_22 AC 335 ms
102,392 KB
testcase_23 AC 217 ms
94,100 KB
testcase_24 AC 102 ms
76,188 KB
testcase_25 AC 331 ms
104,004 KB
testcase_26 AC 305 ms
100,064 KB
testcase_27 AC 298 ms
100,332 KB
testcase_28 AC 158 ms
81,396 KB
testcase_29 AC 153 ms
81,836 KB
testcase_30 AC 330 ms
103,856 KB
testcase_31 AC 247 ms
91,204 KB
testcase_32 AC 133 ms
80,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
xst = set([]);	yst = set([])
for _ in [0] * m:
	X, Y = map(int, input().split())
	X -= 1;	Y -= 1
	xst.add(X + Y)
	yst.add(X - Y)

xlis = [[] for _ in [0] * 2]
ylis = [[] for _ in [0] * 2]
for x in sorted(xst):
	b = abs(x) & 1
	xlis[b].append(x)
for y in sorted(yst):
	b = abs(y) & 1
	ylis[b].append(y)

num = dc = 0
for x in xst:
	b = abs(x) & 1
	num += min(x, n - 1) - max(-n + 1 + x, 0) + 1
	l = bisect_left(ylis[b], max(-x, x - 2 * (n - 1)))
	r = bisect_right(ylis[b], min(2 * (n - 1) - x, x))
	dc += r - l
for y in yst:
	b = abs(y) & 1
	num += min(n - 1 + y, n - 1) - max(y, 0) + 1
	l = bisect_left(xlis[b], max(y, -y))
	r = bisect_right(xlis[b], min(2 * (n - 1) - y, 2 * (n - 1) + y))
	dc += r - l

ans = num - dc // 2
print(ans)
0