結果

問題 No.1997 X Lighting
ユーザー 👑 rin204rin204
提出日時 2022-07-01 22:07:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 311 ms / 2,000 ms
コード長 764 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 95,952 KB
最終ジャッジ日時 2024-05-04 16:31:34
合計ジャッジ時間 7,177 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,096 KB
testcase_01 AC 41 ms
51,968 KB
testcase_02 AC 40 ms
52,480 KB
testcase_03 AC 41 ms
52,096 KB
testcase_04 AC 41 ms
51,840 KB
testcase_05 AC 88 ms
73,984 KB
testcase_06 AC 114 ms
76,160 KB
testcase_07 AC 47 ms
53,248 KB
testcase_08 AC 81 ms
71,680 KB
testcase_09 AC 83 ms
71,680 KB
testcase_10 AC 43 ms
52,608 KB
testcase_11 AC 50 ms
59,520 KB
testcase_12 AC 44 ms
52,864 KB
testcase_13 AC 132 ms
75,964 KB
testcase_14 AC 228 ms
92,252 KB
testcase_15 AC 180 ms
83,328 KB
testcase_16 AC 205 ms
85,888 KB
testcase_17 AC 274 ms
90,960 KB
testcase_18 AC 212 ms
86,144 KB
testcase_19 AC 308 ms
95,952 KB
testcase_20 AC 311 ms
92,916 KB
testcase_21 AC 306 ms
93,180 KB
testcase_22 AC 291 ms
95,828 KB
testcase_23 AC 203 ms
87,592 KB
testcase_24 AC 100 ms
76,924 KB
testcase_25 AC 295 ms
92,880 KB
testcase_26 AC 270 ms
93,780 KB
testcase_27 AC 277 ms
93,908 KB
testcase_28 AC 166 ms
83,712 KB
testcase_29 AC 165 ms
83,328 KB
testcase_30 AC 289 ms
94,296 KB
testcase_31 AC 221 ms
88,088 KB
testcase_32 AC 136 ms
80,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left, bisect_right

n, m = map(int, input().split())
X = set()
Y = set()
for _ in range(m):
    x, y = map(int, input().split())
    X.add(x + y)
    Y.add(x - y)
ans = 0
odd = []
even = []
for x in sorted(X):
    ans += min(x - 1, 2 * n - x + 1)
    if x & 1:
        odd.append(x)
    else:
        even.append(x)

for y in Y:
    xx = 1
    yy = xx - y
    if yy <= 0:
        yy = 1
        xx = yy + y
    mi = xx + yy
    xx = n
    yy = xx - y
    if yy > n:
        yy = n
        xx = yy + y
    ma = xx + yy
    if mi & 1:
        p1 = bisect_left(odd, mi)
        p2 = bisect_right(odd, ma)
    else:
        p1 = bisect_left(even, mi)
        p2 = bisect_right(even, ma)
    ans += (ma - mi) // 2 + 1 - (p2 - p1)
print(ans)


0