結果

問題 No.1997 X Lighting
ユーザー とりゐとりゐ
提出日時 2022-07-01 22:36:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 491 ms / 2,000 ms
コード長 1,205 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 82,156 KB
実行使用メモリ 111,472 KB
最終ジャッジ日時 2024-05-04 16:57:44
合計ジャッジ時間 8,653 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,352 KB
testcase_01 AC 36 ms
52,224 KB
testcase_02 AC 33 ms
52,864 KB
testcase_03 AC 32 ms
52,480 KB
testcase_04 AC 32 ms
52,096 KB
testcase_05 AC 62 ms
72,704 KB
testcase_06 AC 89 ms
76,032 KB
testcase_07 AC 38 ms
54,016 KB
testcase_08 AC 59 ms
71,296 KB
testcase_09 AC 59 ms
69,120 KB
testcase_10 AC 36 ms
52,864 KB
testcase_11 AC 42 ms
53,632 KB
testcase_12 AC 34 ms
52,864 KB
testcase_13 AC 110 ms
76,160 KB
testcase_14 AC 258 ms
104,956 KB
testcase_15 AC 167 ms
84,984 KB
testcase_16 AC 210 ms
89,728 KB
testcase_17 AC 396 ms
103,256 KB
testcase_18 AC 257 ms
98,176 KB
testcase_19 AC 474 ms
111,472 KB
testcase_20 AC 491 ms
107,848 KB
testcase_21 AC 475 ms
107,848 KB
testcase_22 AC 473 ms
110,480 KB
testcase_23 AC 283 ms
94,728 KB
testcase_24 AC 82 ms
76,988 KB
testcase_25 AC 470 ms
107,980 KB
testcase_26 AC 408 ms
102,004 KB
testcase_27 AC 414 ms
102,896 KB
testcase_28 AC 190 ms
88,212 KB
testcase_29 AC 188 ms
87,160 KB
testcase_30 AC 451 ms
109,264 KB
testcase_31 AC 357 ms
102,224 KB
testcase_32 AC 153 ms
82,184 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