結果
問題 | No.2696 Sign Creation |
ユーザー | ゼット |
提出日時 | 2024-03-22 22:53:41 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,074 bytes |
コンパイル時間 | 282 ms |
コンパイル使用メモリ | 81,700 KB |
実行使用メモリ | 335,416 KB |
最終ジャッジ日時 | 2024-03-22 22:54:05 |
合計ジャッジ時間 | 21,188 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 262 ms
258,588 KB |
testcase_01 | AC | 258 ms
251,828 KB |
testcase_02 | AC | 261 ms
251,776 KB |
testcase_03 | AC | 263 ms
251,776 KB |
testcase_04 | AC | 259 ms
251,464 KB |
testcase_05 | AC | 259 ms
251,640 KB |
testcase_06 | AC | 264 ms
251,732 KB |
testcase_07 | AC | 286 ms
251,752 KB |
testcase_08 | AC | 449 ms
297,932 KB |
testcase_09 | AC | 260 ms
251,620 KB |
testcase_10 | AC | 508 ms
297,796 KB |
testcase_11 | AC | 254 ms
251,704 KB |
testcase_12 | AC | 257 ms
251,704 KB |
testcase_13 | AC | 1,480 ms
334,924 KB |
testcase_14 | AC | 817 ms
335,416 KB |
testcase_15 | AC | 795 ms
331,220 KB |
testcase_16 | AC | 1,255 ms
330,484 KB |
testcase_17 | AC | 272 ms
251,596 KB |
testcase_18 | AC | 544 ms
308,212 KB |
testcase_19 | AC | 837 ms
331,136 KB |
testcase_20 | AC | 262 ms
251,704 KB |
testcase_21 | AC | 711 ms
331,976 KB |
testcase_22 | AC | 550 ms
318,872 KB |
testcase_23 | AC | 762 ms
334,320 KB |
testcase_24 | AC | 776 ms
334,264 KB |
testcase_25 | AC | 911 ms
334,320 KB |
testcase_26 | AC | 432 ms
297,484 KB |
testcase_27 | AC | 548 ms
328,952 KB |
testcase_28 | AC | 532 ms
331,140 KB |
testcase_29 | AC | 344 ms
296,640 KB |
testcase_30 | AC | 348 ms
296,532 KB |
testcase_31 | TLE | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
ソースコード
class unif: def __init__(self,n): self.pare=[-1]*n self.size=[1]*n def root(self,x): while self.pare[x]!=-1: x=self.pare[x] return x def unite(self,u,v): rootu=self.root(u) rootv=self.root(v) if rootu!=rootv: if self.size[rootu]>=self.size[rootv]: self.pare[rootv]=rootu self.size[rootu]+=self.size[rootv] else: self.pare[rootu]=rootv self.size[rootv]+=self.size[rootu] def same(self,s,t): return self.root(s)==self.root(t) H,W,N,D=map(int,input().split()) C=set() A=[{} for i in range(2*(H+1))] T={} L=[] for i in range(N): x,y=map(int,input().split()) L.append((x,y)) T[x*10**10+y]=i Z=unif(N) for i in range(N): x,y=L[i][:] for dx in range(-D,D+1): k=D-abs(dx) for dy in range(-k,k+1): x2,y2=x+dx,y+dy if x2<=0 or x2>=H+1 or y2<=0 or y2>=W+1: continue w=x2*10**10+y2 if w in T: pos=T[w] Z.unite(i,pos) count=0 b=set() for i in range(N): p=Z.root(i) if Z.size[p]>1: b.add(p) count=len(b) h=[] u=[0]*N t=[0]*N for i in range(N): p=Z.root(i) k=Z.size[p] u[i]=p t[i]=k ans1=10**10 ans2=-10**10 used=0 D2=[set() for i in range(4*10**6)] e={} f=[0]*(4*10**6) for i in range(N): x,y=L[i][:] for dx in range(-D,D+1): k=D-abs(dx) for dy in range(-k,k+1): x2,y2=x+dx,y+dy if x==x2 and y==y2: continue if x2<=0 or x2>=H+1 or y2<=0 or y2>=W+1: continue n=t[i] pos=u[i] w=x2*10**10+y2 if not w in e: e[w]=used D2[used].add(pos) used+=1 if w in T: f[used-1]=0 else: f[used-1]=1 else: p=e[w] D2[p].add(pos) if used<H*W: ans1=min(ans1,count) ans2=max(ans2,count) for i in range(used): c=0 k=0 if f[i]==0: continue for pos in D2[i]: if Z.size[pos]==1: c=1 else: k+=1 if k==0 and c==1: ans1=min(ans1,count+1) ans2=max(ans2,count+1) else: ans1=min(ans1,count+1-k) ans2=max(ans2,count+1-k) print(ans1,ans2)