結果
問題 | No.871 かえるのうた |
ユーザー | kawacchu |
提出日時 | 2019-08-30 22:11:40 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,506 bytes |
コンパイル時間 | 114 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 32,892 KB |
最終ジャッジ日時 | 2024-05-01 18:15:44 |
合計ジャッジ時間 | 5,117 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
16,384 KB |
testcase_01 | WA | - |
testcase_02 | AC | 32 ms
10,880 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 33 ms
11,008 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 34 ms
11,264 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 156 ms
26,816 KB |
testcase_15 | WA | - |
testcase_16 | TLE | - |
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 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
ソースコード
import sys input = sys.stdin.readline from bisect import * from collections import deque class UnionFind: def __init__(self, num): self.rank = [0] * num self.par = [i for i in range(num)] self.n = num def find_root(self, node): if self.par[node] == node: return node else: self.par[node] = self.find_root(self.par[node]) return self.par[node] def same_root(self, x, y): return self.find_root(x) == self.find_root(y) def union(self, x, y): x = self.find_root(x) y = self.find_root(y) if x == y: return if self.rank[x] > self.rank[y]: self.par[y] = x else: self.par[x] = y if self.rank[x] == self.rank[y]: self.rank[y] += 1 N,K = map(int,input().split()) X = list(map(int,input().split())) A = list(map(int,input().split())) UF = UnionFind(N) q = deque([K-1]) while q : indn = q.popleft() x = X[indn] indl = bisect_left(X,x-A[indn]) for j in range(indl,indn) : if UF.same_root(j,indn) : continue UF.union(j,indn) q.append(j) q = deque([K-1]) while q : indn = q.popleft() indr = bisect_right(X,x+A[indn])-1 for j in range(indn+1,indr+1) : if UF.same_root(indn,j) : continue UF.union(indn,j) q.append(j) ans = 0 for i in range(N) : if UF.same_root(i,K-1) : ans += 1 print(ans)