結果

問題 No.1997 X Lighting
ユーザー ShirotsumeShirotsume
提出日時 2022-04-22 00:51:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 363 ms / 2,000 ms
コード長 977 bytes
コンパイル時間 1,044 ms
コンパイル使用メモリ 86,844 KB
実行使用メモリ 121,392 KB
最終ジャッジ日時 2023-09-05 07:19:46
合計ジャッジ時間 11,518 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,236 KB
testcase_01 AC 75 ms
71,292 KB
testcase_02 AC 75 ms
70,924 KB
testcase_03 AC 75 ms
70,968 KB
testcase_04 AC 74 ms
71,180 KB
testcase_05 AC 122 ms
77,936 KB
testcase_06 AC 156 ms
81,892 KB
testcase_07 AC 82 ms
71,172 KB
testcase_08 AC 116 ms
77,840 KB
testcase_09 AC 114 ms
77,712 KB
testcase_10 AC 78 ms
71,464 KB
testcase_11 AC 84 ms
75,568 KB
testcase_12 AC 77 ms
71,136 KB
testcase_13 AC 196 ms
87,880 KB
testcase_14 AC 297 ms
121,308 KB
testcase_15 AC 208 ms
87,344 KB
testcase_16 AC 225 ms
92,068 KB
testcase_17 AC 322 ms
109,240 KB
testcase_18 AC 243 ms
96,596 KB
testcase_19 AC 362 ms
121,364 KB
testcase_20 AC 363 ms
116,636 KB
testcase_21 AC 357 ms
116,560 KB
testcase_22 AC 363 ms
121,392 KB
testcase_23 AC 254 ms
102,188 KB
testcase_24 AC 144 ms
78,816 KB
testcase_25 AC 354 ms
116,448 KB
testcase_26 AC 323 ms
111,364 KB
testcase_27 AC 324 ms
121,036 KB
testcase_28 AC 201 ms
87,360 KB
testcase_29 AC 195 ms
87,104 KB
testcase_30 AC 346 ms
120,740 KB
testcase_31 AC 281 ms
102,152 KB
testcase_32 AC 179 ms
83,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

n, m = map(int,input().split())
xy = [list(map(int,input().split())) for _ in range(m)]

plus_odd = []
plus_even = []
minus_odd = []
minus_even = []
ans = 0
x_set = set()
y_set = set()
for i in range(m):
    x, y = xy[i]
    X = x + y - 2
    Y = x - y
    if X not in x_set:
        ans += min(X, n - 1) - max(1 + X - n, 0) + 1
        x_set.add(X)
    if Y not in y_set:
        ans += min(n - 1 + Y, n - 1) - max(Y, 0) + 1
        y_set.add(Y)

for v in y_set:
    if v % 2:
        plus_odd.append(abs(v))
    else:
        plus_even.append(abs(v))
for v in x_set:
    if v % 2:
        minus_odd.append(v)
    else:
        minus_even.append(v)

minus_odd.sort()
minus_even.sort()
plus_even.sort()
plus_odd.sort()
for y in plus_odd:
    ans -= max(0, bisect.bisect(minus_odd, 2 * (n - 1) - y) - bisect.bisect(minus_odd, y - 1))
for y in plus_even:
    ans -= max(0, bisect.bisect(minus_even, 2 * (n - 1) - y) - bisect.bisect(minus_even, y - 1))
print(ans)

0