結果

問題 No.1997 X Lighting
ユーザー first_vilfirst_vil
提出日時 2022-07-01 23:54:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 281 ms / 2,000 ms
コード長 1,323 bytes
コンパイル時間 1,654 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 97,780 KB
最終ジャッジ日時 2023-08-17 11:41:23
合計ジャッジ時間 8,403 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,364 KB
testcase_01 AC 70 ms
71,480 KB
testcase_02 AC 69 ms
71,428 KB
testcase_03 AC 69 ms
71,296 KB
testcase_04 AC 68 ms
71,104 KB
testcase_05 AC 106 ms
76,792 KB
testcase_06 AC 106 ms
77,256 KB
testcase_07 AC 71 ms
71,172 KB
testcase_08 AC 90 ms
76,824 KB
testcase_09 AC 87 ms
76,604 KB
testcase_10 AC 69 ms
71,316 KB
testcase_11 AC 75 ms
75,260 KB
testcase_12 AC 71 ms
71,420 KB
testcase_13 AC 117 ms
77,312 KB
testcase_14 AC 182 ms
97,780 KB
testcase_15 AC 151 ms
83,284 KB
testcase_16 AC 167 ms
85,696 KB
testcase_17 AC 267 ms
90,720 KB
testcase_18 AC 185 ms
89,196 KB
testcase_19 AC 279 ms
97,028 KB
testcase_20 AC 261 ms
94,816 KB
testcase_21 AC 263 ms
95,488 KB
testcase_22 AC 281 ms
97,672 KB
testcase_23 AC 189 ms
85,596 KB
testcase_24 AC 112 ms
77,872 KB
testcase_25 AC 253 ms
95,212 KB
testcase_26 AC 231 ms
89,460 KB
testcase_27 AC 231 ms
90,080 KB
testcase_28 AC 154 ms
83,392 KB
testcase_29 AC 149 ms
83,208 KB
testcase_30 AC 254 ms
96,728 KB
testcase_31 AC 202 ms
88,068 KB
testcase_32 AC 135 ms
79,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left
import sys

int1 = lambda x: int(x) - 1

# input = lambda: sys.stdin.buffer.readline()
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
i1 = lambda: int1(input())
mi = lambda: map(int, input().split())
mi1 = lambda: map(int1, input().split())
li = lambda: list(mi())
li1 = lambda: list(mi1())
lli = lambda n: [li() for _ in range(n)]

INF = float("inf")
mod = int(1e9 + 7)
# mod = 998244353

n, m = mi()
down = set()
left_down = set()
left_up = set()
bottom_up = set()
for _ in range(m):
    y, x = mi()
    if y <= x:
        down.add(x - y)
    else:
        left_down.add(y - x)
    if y + x <= n + 1:
        left_up.add(y + x)
    else:
        bottom_up.add(y + x - n - 1)

ans = 0
for x in down:
    ans += n - x
for y in left_down:
    ans += n - y
for y in left_up:
    ans += y - 1
for x in bottom_up:
    ans += n - x


def oe(s):
    res = [[], []]
    for x in s:
        res[x & 1].append(x)
    res[0].sort()
    res[1].sort()
    return res


d = oe(down)
ld = oe(left_down)
lu = oe(left_up)
bu = oe(bottom_up)
for y in left_up:
    ans -= bisect_left(d[y & 1], y)
    ans -= bisect_left(ld[y & 1], y)
for y in left_down:
    ans -= bisect_left(bu[(n + 1 - y) & 1], n - y)
for x in down:
    ans -= bisect_left(bu[(x & 1) ^ (~n & 1)], n - x)
print(ans)
0