結果
問題 | No.2786 RMQ on Grid Path |
ユーザー | ゼット |
提出日時 | 2024-06-14 22:33:14 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,476 bytes |
コンパイル時間 | 555 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 150,916 KB |
最終ジャッジ日時 | 2024-06-14 22:33:25 |
合計ジャッジ時間 | 10,747 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,480 KB |
testcase_01 | AC | 37 ms
52,992 KB |
testcase_02 | AC | 90 ms
76,032 KB |
testcase_03 | AC | 83 ms
76,160 KB |
testcase_04 | AC | 94 ms
76,032 KB |
testcase_05 | AC | 92 ms
76,416 KB |
testcase_06 | AC | 89 ms
76,416 KB |
testcase_07 | AC | 87 ms
76,284 KB |
testcase_08 | AC | 88 ms
76,160 KB |
testcase_09 | AC | 89 ms
76,544 KB |
testcase_10 | AC | 90 ms
76,416 KB |
testcase_11 | AC | 92 ms
76,160 KB |
testcase_12 | TLE | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
ソースコード
class dsu(): n=1 parent_or_size=[-1 for i in range(n)] def __init__(self,N): self.n=N self.parent_or_size=[-1 for i in range(N)] def merge(self,a,b): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) assert 0<=b<self.n, "0<=b<n,b={0},n={1}".format(b,self.n) x=self.leader(a) y=self.leader(b) if x==y: return x if (-self.parent_or_size[x]<-self.parent_or_size[y]): x,y=y,x self.parent_or_size[x]+=self.parent_or_size[y] self.parent_or_size[y]=x return x def same(self,a,b): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) assert 0<=b<self.n, "0<=b<n,b={0},n={1}".format(b,self.n) return self.leader(a)==self.leader(b) def leader(self,a): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) if (self.parent_or_size[a]<0): return a self.parent_or_size[a]=self.leader(self.parent_or_size[a]) return self.parent_or_size[a] def size(self,a): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) return -self.parent_or_size[self.leader(a)] def groups(self): leader_buf=[0 for i in range(self.n)] group_size=[0 for i in range(self.n)] for i in range(self.n): leader_buf[i]=self.leader(i) group_size[leader_buf[i]]+=1 result=[[] for i in range(self.n)] for i in range(self.n): result[leader_buf[i]].append(i) result2=[] for i in range(self.n): if len(result[i])>0: result2.append(result[i]) return result2 H,W=map(int,input().split()) A=[list(map(int,input().split())) for i in range(H)] C=set() q=[] Q=int(input()) for i in range(Q): a,b,c,d=map(int,input().split()) q.append(((a-1)*W+b-1,(c-1)*W+d-1)) C.add(i) L=[[] for i in range(H*W+1)] for i in range(H): for j in range(W): if i<H-1: x=A[i][j] y=A[i+1][j] z=max(x,y) L[z].append((i*W+j,(i+1)*W+j)) if j<W-1: x=A[i][j] y=A[i][j+1] z=max(x,y) L[z].append((i*W+j,i*W+j+1)) result=[0]*Q Z=dsu(H*W) for x in range(1,H*W+1): if len(L[x])==0: continue for B in L[x]: pos1,pos2=B[:] Z.merge(pos1,pos2) l=[] for k in C: p1,p2=q[k][:] if Z.same(p1,p2)==True: l.append(k) result[k]=x for k in l: C.remove(k) for i in range(Q): print(result[i])