結果

問題 No.1997 X Lighting
ユーザー Kiri8128Kiri8128
提出日時 2022-07-01 23:23:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 313 ms / 2,000 ms
コード長 940 bytes
コンパイル時間 372 ms
コンパイル使用メモリ 86,808 KB
実行使用メモリ 162,072 KB
最終ジャッジ日時 2023-08-17 11:08:57
合計ジャッジ時間 7,622 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,224 KB
testcase_01 AC 68 ms
71,228 KB
testcase_02 AC 66 ms
71,220 KB
testcase_03 AC 68 ms
71,248 KB
testcase_04 AC 66 ms
71,364 KB
testcase_05 AC 94 ms
76,832 KB
testcase_06 AC 117 ms
77,480 KB
testcase_07 AC 72 ms
71,416 KB
testcase_08 AC 93 ms
76,860 KB
testcase_09 AC 90 ms
76,620 KB
testcase_10 AC 69 ms
71,196 KB
testcase_11 AC 71 ms
71,308 KB
testcase_12 AC 68 ms
71,340 KB
testcase_13 AC 135 ms
77,320 KB
testcase_14 AC 227 ms
137,320 KB
testcase_15 AC 156 ms
92,748 KB
testcase_16 AC 180 ms
103,196 KB
testcase_17 AC 275 ms
141,540 KB
testcase_18 AC 199 ms
104,764 KB
testcase_19 AC 309 ms
161,172 KB
testcase_20 AC 307 ms
139,140 KB
testcase_21 AC 310 ms
138,224 KB
testcase_22 AC 313 ms
161,588 KB
testcase_23 AC 222 ms
123,580 KB
testcase_24 AC 117 ms
77,648 KB
testcase_25 AC 310 ms
154,276 KB
testcase_26 AC 283 ms
150,792 KB
testcase_27 AC 295 ms
152,864 KB
testcase_28 AC 164 ms
95,784 KB
testcase_29 AC 162 ms
92,992 KB
testcase_30 AC 311 ms
162,072 KB
testcase_31 AC 243 ms
128,400 KB
testcase_32 AC 146 ms
87,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
n = N - 1
pp = set()
mm = set()
ans = 0
for _ in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    p = x + y
    m = x - y
    if p not in pp:
        pp.add(p)
        ans += N - abs(p - n)
    if m not in mm:
        mm.add(m)
        ans += N - abs(m)

pp = sorted(pp)
mm = sorted(mm)
pp = sorted([n - abs(n - a) for a in pp])
mm = sorted([abs(a) for a in mm])
ppe = [a for a in pp if a % 2 == 0]
ppo = [a for a in pp if a % 2 == 1]
mme = [a for a in mm if a % 2 == 0]
mmo = [a for a in mm if a % 2 == 1]
def calc(pp, mm):
    SS = sorted(set(pp + mm))
    IA = {a: i for i, a in enumerate(SS)}
    pp = [IA[a] for a in pp]
    mm = [IA[a] for a in mm]
    C = [0] * (len(SS) + 1)
    for a in mm:
        C[a] += 1
    for i in range(len(SS)):
        C[i+1] += C[i]
    ret = 0
    for a in pp:
        ret += C[a]
    return ret
ans -= calc(ppe, mme) + calc(ppo, mmo)
print(ans)
0