Skip to content

Commit

Permalink
22.08.01
Browse files Browse the repository at this point in the history
  • Loading branch information
delena0702 authored Aug 1, 2022
1 parent 6068c6c commit 2346298
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
48 changes: 48 additions & 0 deletions BAEKJOON/2310_어드벤처_게임.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from collections import deque
import sys
def input(): return sys.stdin.readline().strip()

while True:
N = int(input())

if N == 0:
break

nodes = [0] * (N + 1)
edges = [[] for _ in range(N + 1)]
edges[0] = [1]
for here in range(1, N + 1):
arr = input().split()

if arr[0] == 'L':
nodes[here] = int(arr[1])
else:
nodes[here] = -int(arr[1])

for there in arr[2:-1]:
edges[here].append(int(there))

queue = deque([(0, 0)])
dist = [-1] * (N + 1)
dist[0] = 0

while queue:
here, cost = queue.popleft()

if here == N:
print("Yes")
break

for there in edges[here]:
if nodes[there] >= 0:
ncost = max(cost, nodes[there])
else:
ncost = cost + nodes[there]

if ncost <= dist[there]:
continue

dist[there] = ncost
queue.append((there, ncost))
else:
print("No")
27 changes: 27 additions & 0 deletions BAEKJOON/7578_공장.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys
def input(): return sys.stdin.readline().strip()

def get(idx):
retval = 0
while idx:
retval = retval + fenwick[idx]
idx = idx - (-idx & idx)
return retval

def update(idx):
while idx <= N:
fenwick[idx] = fenwick[idx] + 1
idx = idx + (-idx & idx)

N = int(input())
data = input().split()
dic = {}
for i in range(N):
dic[data[i]] = i

fenwick = [0] * (N + 1)
answer = 0
for i, key in enumerate(input().split()):
answer = answer + i - get(dic[key] + 1)
update(dic[key] + 1)
print(answer)

0 comments on commit 2346298

Please sign in to comment.