結果

問題 No.1997 X Lighting
ユーザー mkawa2mkawa2
提出日時 2022-07-01 22:45:14
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 1,257 bytes
コンパイル時間 258 ms
コンパイル使用メモリ 87,256 KB
実行使用メモリ 96,960 KB
最終ジャッジ日時 2023-08-17 10:20:19
合計ジャッジ時間 7,142 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,128 KB
testcase_01 AC 69 ms
71,508 KB
testcase_02 AC 68 ms
71,112 KB
testcase_03 AC 68 ms
71,252 KB
testcase_04 AC 68 ms
71,580 KB
testcase_05 AC 101 ms
77,424 KB
testcase_06 AC 103 ms
77,308 KB
testcase_07 AC 71 ms
71,560 KB
testcase_08 AC 87 ms
77,016 KB
testcase_09 AC 86 ms
76,836 KB
testcase_10 AC 69 ms
71,332 KB
testcase_11 AC 75 ms
75,404 KB
testcase_12 AC 69 ms
71,436 KB
testcase_13 AC 115 ms
77,528 KB
testcase_14 AC 202 ms
96,288 KB
testcase_15 AC 147 ms
83,964 KB
testcase_16 AC 157 ms
84,060 KB
testcase_17 AC 216 ms
91,628 KB
testcase_18 AC 171 ms
87,624 KB
testcase_19 AC 246 ms
96,796 KB
testcase_20 AC 241 ms
96,700 KB
testcase_21 AC 243 ms
96,792 KB
testcase_22 AC 237 ms
96,960 KB
testcase_23 AC 172 ms
87,572 KB
testcase_24 AC 104 ms
77,828 KB
testcase_25 AC 241 ms
96,652 KB
testcase_26 AC 222 ms
94,552 KB
testcase_27 AC 220 ms
92,596 KB
testcase_28 AC 143 ms
83,860 KB
testcase_29 AC 141 ms
83,932 KB
testcase_30 AC 241 ms
96,612 KB
testcase_31 AC 190 ms
87,804 KB
testcase_32 AC 127 ms
81,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = (1 << 63)-1
inf = (1 << 31)-1
md = 10**9+7
# md = 998244353

from bisect import bisect_left

n, m = LI()
ss = set()
dd = set()
for _ in range(m):
    i, j = LI1()
    ss.add(i+j)
    dd.add(i-j)
# pDB(ss,dd)

eo = [[], []]
ans = 0
for s in ss:
    ans += n-abs(n-1-s)
    eo[s & 1].append(s)
    # pDB(s,ans)
for d in dd:
    ans += n-abs(d)
    # pDB(d,ans)

eo[0].sort()
eo[1].sort()
for d in dd:
    l = max(d, -d)
    r = min(2*n-d, 2*n+d)
    if l >= r: continue
    li = bisect_left(eo[d & 1], l)
    ri = bisect_left(eo[d & 1], r)
    ans -= ri-li
    # pDB(d,l,r,li,ri,ans)

print(ans)
0