結果

問題 No.1997 X Lighting
ユーザー とりゐとりゐ
提出日時 2022-07-01 22:36:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 620 ms / 2,000 ms
コード長 1,205 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 110,348 KB
最終ジャッジ日時 2023-08-17 10:08:45
合計ジャッジ時間 11,308 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,304 KB
testcase_01 AC 76 ms
71,152 KB
testcase_02 AC 78 ms
71,236 KB
testcase_03 AC 74 ms
71,196 KB
testcase_04 AC 74 ms
71,208 KB
testcase_05 AC 109 ms
77,764 KB
testcase_06 AC 129 ms
77,488 KB
testcase_07 AC 78 ms
71,196 KB
testcase_08 AC 103 ms
76,812 KB
testcase_09 AC 100 ms
76,740 KB
testcase_10 AC 74 ms
71,160 KB
testcase_11 AC 78 ms
71,136 KB
testcase_12 AC 76 ms
71,364 KB
testcase_13 AC 148 ms
77,492 KB
testcase_14 AC 321 ms
106,552 KB
testcase_15 AC 233 ms
85,880 KB
testcase_16 AC 279 ms
92,560 KB
testcase_17 AC 507 ms
103,780 KB
testcase_18 AC 321 ms
97,768 KB
testcase_19 AC 595 ms
110,348 KB
testcase_20 AC 620 ms
109,036 KB
testcase_21 AC 619 ms
109,008 KB
testcase_22 AC 596 ms
109,276 KB
testcase_23 AC 366 ms
98,232 KB
testcase_24 AC 125 ms
78,008 KB
testcase_25 AC 587 ms
108,460 KB
testcase_26 AC 519 ms
103,148 KB
testcase_27 AC 520 ms
103,596 KB
testcase_28 AC 258 ms
92,040 KB
testcase_29 AC 261 ms
92,436 KB
testcase_30 AC 571 ms
108,112 KB
testcase_31 AC 428 ms
101,428 KB
testcase_32 AC 213 ms
83,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

m,n=map(int,input().split())

s=set()
t=set()

s0query=[]
s1query=[]
#t0query=[]
#t1query=[]

ans=0
for i in range(n):
  x,y=map(int,input().split())
  if x+y not in s:
    s.add(x+y)
    lx,ly=1,x+y-1
    if ly>m:
      ly=m
      lx=x+y-m
    rx,ry=x+y-1,1
    if rx>m:
      rx=m
      ry=x+y-m
    if (x+y)%2==0:
      #t0query.append((2*(lx-ly)-1,1))
      #t0query.append((2*(rx-ry)+1,-1))
      s0query.append((2*(x+y),0))
    else:
      #t1query.append((2*(lx-ly)-1,1))
      #t1query.append((2*(rx-ry)+1,-1))
      s1query.append((2*(x+y),0))
    ans+=rx-lx+1

  if x-y not in t:
    t.add(x-y)
    lx,ly=1,1+y-x
    if ly<1:
      lx,ly=x-y+1,1
    rx,ry=m,m+y-x
    if ry>m:
      rx,ry=x-y+m,m
    if (x+y)%2==0:
      s0query.append((2*(lx+ly)-1,1))
      s0query.append((2*(rx+ry)+1,-1))
      #t0query.append((2*(x-y),0))
    else:
      s1query.append((2*(lx+ly)-1,1))
      s1query.append((2*(rx+ry)+1,-1))
      #t1query.append((2*(x-y),0))
    ans+=rx-lx+1

def calc(a):
  a.sort(key=lambda x:x[0])
  ans=0
  cnt=0
  for _,i in a:
    if i==1:
      cnt+=1
    if i==0:
      ans+=cnt
    if i==-1:
      cnt-=1
  return ans
#print(ans)
ans-=calc(s0query)
ans-=calc(s1query)
print(ans)
0