結果

問題 No.1997 X Lighting
ユーザー 👑 rin204rin204
提出日時 2022-07-01 22:07:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 299 ms / 2,000 ms
コード長 764 bytes
コンパイル時間 234 ms
コンパイル使用メモリ 86,876 KB
実行使用メモリ 99,428 KB
最終ジャッジ日時 2023-08-17 09:40:30
合計ジャッジ時間 7,367 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,224 KB
testcase_01 AC 70 ms
71,352 KB
testcase_02 AC 67 ms
71,592 KB
testcase_03 AC 66 ms
71,352 KB
testcase_04 AC 67 ms
71,288 KB
testcase_05 AC 101 ms
77,568 KB
testcase_06 AC 121 ms
77,436 KB
testcase_07 AC 71 ms
71,420 KB
testcase_08 AC 93 ms
76,716 KB
testcase_09 AC 95 ms
76,872 KB
testcase_10 AC 68 ms
71,420 KB
testcase_11 AC 74 ms
75,428 KB
testcase_12 AC 69 ms
71,172 KB
testcase_13 AC 139 ms
77,468 KB
testcase_14 AC 218 ms
93,664 KB
testcase_15 AC 180 ms
84,736 KB
testcase_16 AC 212 ms
87,396 KB
testcase_17 AC 258 ms
92,608 KB
testcase_18 AC 211 ms
87,556 KB
testcase_19 AC 299 ms
98,796 KB
testcase_20 AC 289 ms
95,060 KB
testcase_21 AC 287 ms
95,056 KB
testcase_22 AC 286 ms
99,428 KB
testcase_23 AC 207 ms
88,712 KB
testcase_24 AC 119 ms
78,108 KB
testcase_25 AC 279 ms
93,764 KB
testcase_26 AC 259 ms
94,672 KB
testcase_27 AC 262 ms
94,988 KB
testcase_28 AC 168 ms
84,952 KB
testcase_29 AC 173 ms
84,708 KB
testcase_30 AC 279 ms
93,824 KB
testcase_31 AC 225 ms
88,816 KB
testcase_32 AC 154 ms
82,808 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