結果
問題 | No.1997 X Lighting |
ユーザー |
![]() |
提出日時 | 2022-07-01 22:36:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 577 ms / 2,000 ms |
コード長 | 1,205 bytes |
コンパイル時間 | 834 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 111,452 KB |
最終ジャッジ日時 | 2024-11-26 06:04:32 |
合計ジャッジ時間 | 9,819 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
m,n=map(int,input().split())s=set()t=set()s0query=[]s1query=[]#t0query=[]#t1query=[]ans=0for 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-1if ly>m:ly=mlx=x+y-mrx,ry=x+y-1,1if rx>m:rx=mry=x+y-mif (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+1if x-y not in t:t.add(x-y)lx,ly=1,1+y-xif ly<1:lx,ly=x-y+1,1rx,ry=m,m+y-xif ry>m:rx,ry=x-y+m,mif (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+1def calc(a):a.sort(key=lambda x:x[0])ans=0cnt=0for _,i in a:if i==1:cnt+=1if i==0:ans+=cntif i==-1:cnt-=1return ans#print(ans)ans-=calc(s0query)ans-=calc(s1query)print(ans)