結果
問題 | No.2786 RMQ on Grid Path |
ユーザー | detteiuu |
提出日時 | 2024-07-07 05:29:21 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,136 bytes |
コンパイル時間 | 280 ms |
コンパイル使用メモリ | 81,980 KB |
実行使用メモリ | 283,696 KB |
最終ジャッジ日時 | 2024-07-07 05:31:16 |
合計ジャッジ時間 | 102,678 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
52,224 KB |
testcase_01 | AC | 37 ms
52,864 KB |
testcase_02 | AC | 98 ms
76,672 KB |
testcase_03 | AC | 94 ms
76,464 KB |
testcase_04 | AC | 88 ms
76,812 KB |
testcase_05 | AC | 96 ms
76,928 KB |
testcase_06 | AC | 94 ms
76,800 KB |
testcase_07 | AC | 102 ms
76,556 KB |
testcase_08 | AC | 85 ms
76,532 KB |
testcase_09 | AC | 92 ms
76,140 KB |
testcase_10 | AC | 89 ms
76,160 KB |
testcase_11 | AC | 100 ms
77,008 KB |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | AC | 5,546 ms
261,216 KB |
testcase_19 | AC | 5,911 ms
280,052 KB |
testcase_20 | AC | 5,662 ms
265,592 KB |
testcase_21 | AC | 5,791 ms
283,472 KB |
testcase_22 | AC | 4,415 ms
238,368 KB |
testcase_23 | AC | 4,382 ms
243,472 KB |
testcase_24 | AC | 3,074 ms
272,680 KB |
testcase_25 | AC | 3,071 ms
271,312 KB |
testcase_26 | AC | 3,072 ms
270,184 KB |
testcase_27 | AC | 1,755 ms
135,672 KB |
testcase_28 | AC | 1,056 ms
124,452 KB |
testcase_29 | AC | 4,963 ms
240,328 KB |
testcase_30 | AC | 1,299 ms
122,092 KB |
testcase_31 | AC | 641 ms
90,772 KB |
testcase_32 | AC | 2,032 ms
253,184 KB |
testcase_33 | AC | 246 ms
117,796 KB |
testcase_34 | AC | 2,140 ms
261,304 KB |
testcase_35 | AC | 2,208 ms
258,492 KB |
testcase_36 | AC | 2,183 ms
260,608 KB |
ソースコード
from sys import stdin class UnionFind: def __init__(self,n): self.n = n self.parent_size = [-1]*n def leader(self,a): if self.parent_size[a] < 0: return a self.parent_size[a] = self.leader(self.parent_size[a]) return self.parent_size[a] def merge(self,a,b): x, y = self.leader(a), self.leader(b) if x == y: return if abs(self.parent_size[x]) < abs(self.parent_size[y]): x, y = y, x self.parent_size[x] += self.parent_size[y] self.parent_size[y] = x return def same(self,a,b): return self.leader(a) == self.leader(b) def size(self,a): return abs(self.parent_size[self.leader(a)]) def groups(self): result = [[] for _ in range(self.n)] for i in range(self.n): result[self.leader(i)].append(i) return [r for r in result if r != []] H, W = map(int, input().split()) A = [list(map(int, stdin.readline().split())) for _ in range(H)] Q = int(input()) query = [list(map(int, stdin.readline().split())) for _ in range(Q)] def IDX(i, j): return i*W+j edge = [] for i in range(H): for j in range(W): if i+1 < H: edge.append((IDX(i, j), IDX(i+1, j), max(A[i][j], A[i+1][j]))) if j+1 < W: edge.append((IDX(i, j), IDX(i, j+1), max(A[i][j:j+2]))) edge.sort(key=lambda x:x[2]) left = [0]*Q right = [len(edge)]*Q mid = [[] for _ in range(len(edge)+1)] for i in range(Q): mid[len(edge)//2].append(i) cnt = 0 while cnt < Q: UF = UnionFind(H*W) for i in range(len(edge)+1): while mid[i]: idx = mid[i].pop() sh, sw, gh, gw = query[idx] if UF.same(IDX(sh-1, sw-1), IDX(gh-1, gw-1)): right[idx] = i else: left[idx] = i if left[idx]+1 == right[idx]: cnt += 1 else: mid[(left[idx]+right[idx])//2].append(idx) if i < len(edge): v, w, c = edge[i] UF.merge(v, w) for i in range(Q): print(edge[left[i]][2])