結果

問題 No.1997 X Lighting
ユーザー MasKoaTSMasKoaTS
提出日時 2022-03-28 18:29:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,140 ms / 2,000 ms
コード長 852 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 29,936 KB
最終ジャッジ日時 2024-04-28 12:02:52
合計ジャッジ時間 15,788 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,752 KB
testcase_01 AC 25 ms
10,880 KB
testcase_02 AC 29 ms
10,752 KB
testcase_03 AC 28 ms
10,880 KB
testcase_04 AC 28 ms
10,752 KB
testcase_05 AC 42 ms
10,880 KB
testcase_06 AC 113 ms
11,264 KB
testcase_07 AC 28 ms
10,752 KB
testcase_08 AC 36 ms
10,752 KB
testcase_09 AC 32 ms
10,880 KB
testcase_10 AC 26 ms
10,880 KB
testcase_11 AC 29 ms
10,752 KB
testcase_12 AC 27 ms
10,880 KB
testcase_13 AC 171 ms
11,648 KB
testcase_14 AC 941 ms
29,432 KB
testcase_15 AC 316 ms
17,444 KB
testcase_16 AC 400 ms
18,300 KB
testcase_17 AC 871 ms
27,072 KB
testcase_18 AC 491 ms
19,648 KB
testcase_19 AC 1,032 ms
28,156 KB
testcase_20 AC 1,140 ms
29,936 KB
testcase_21 AC 1,124 ms
29,808 KB
testcase_22 AC 1,036 ms
28,732 KB
testcase_23 AC 588 ms
20,568 KB
testcase_24 AC 49 ms
11,264 KB
testcase_25 AC 1,103 ms
29,396 KB
testcase_26 AC 926 ms
27,768 KB
testcase_27 AC 930 ms
28,036 KB
testcase_28 AC 322 ms
17,716 KB
testcase_29 AC 305 ms
17,752 KB
testcase_30 AC 1,068 ms
28,588 KB
testcase_31 AC 692 ms
21,716 KB
testcase_32 AC 206 ms
13,696 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