complete 1326.py and 11000.py
This commit is contained in:
23
zeta_python/completed/11000.py
Normal file
23
zeta_python/completed/11000.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import sys
|
||||
import heapq
|
||||
|
||||
input = sys.stdin.readline
|
||||
|
||||
|
||||
def solve(N, Cl):
|
||||
Cl.sort()
|
||||
|
||||
pq = []
|
||||
heapq.heappush(pq, Cl[0][1])
|
||||
for i in range(1, N):
|
||||
if pq[0] <= Cl[i][0]:
|
||||
heapq.heappop(pq)
|
||||
heapq.heappush(pq, Cl[i][1])
|
||||
|
||||
return len(pq)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
N = int(input())
|
||||
Cl = [tuple(map(int, input().split())) for _ in range(N)]
|
||||
print(solve(N, Cl))
|
||||
38
zeta_python/completed/1326.py
Normal file
38
zeta_python/completed/1326.py
Normal file
@@ -0,0 +1,38 @@
|
||||
def solve(N, P, a, b):
|
||||
a -= 1
|
||||
b -= 1
|
||||
D = []
|
||||
D.append((a, 0))
|
||||
visited = [2147483647] * N
|
||||
visited[a] = 0
|
||||
if b == a:
|
||||
return 0
|
||||
while D:
|
||||
now, cost = D.pop(0)
|
||||
|
||||
if now == b:
|
||||
return cost
|
||||
|
||||
from_now_on = now - P[now]
|
||||
# - dir
|
||||
while from_now_on >= 0:
|
||||
if visited[from_now_on] > cost + 1:
|
||||
visited[from_now_on] = cost + 1
|
||||
D.append((from_now_on, cost + 1))
|
||||
from_now_on -= P[now]
|
||||
from_now_on = now + P[now]
|
||||
# + dir
|
||||
while from_now_on < N:
|
||||
if visited[from_now_on] > cost + 1:
|
||||
visited[from_now_on] = cost + 1
|
||||
D.append((from_now_on, cost + 1))
|
||||
from_now_on += P[now]
|
||||
|
||||
return -1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
N = int(input())
|
||||
P = list(map(int, input().split()))
|
||||
a, b = map(int, input().split())
|
||||
print(solve(N, P, a, b))
|
||||
Reference in New Issue
Block a user