def main():
N = int(input())
AS = list(map(int, input().split()))
BS = list(map(int, input().split()))
ret = 0
for i in range(N):
ret += AS[i] * BS[i]
if ret == 0:
print("Yes")
else:
print("No")
def main():
N, C = map(int, input().split())
from collections import defaultdict
diff = defaultdict(int)
for _n in range(N):
a, b, c = map(int, input().split())
diff[a] += c
diff[b + 1] -= c
keys = list(sorted(diff))
cost = 0
ret = 0
for i in range(1, len(keys)):
cost += diff[keys[i - 1]]
days = keys[i] - keys[i - 1]
ret += min(cost, C) * days
print(ret)
def main():
N, M = map(int, input().split())
AS = list(map(int, input().split()))
from collections import defaultdict
edges = defaultdict(list)
for _i in range(M):
frm, to = map(int, input().split())
edges[frm - 1].append(to - 1) # -1 for 1-origin vertexes
INF = 9223372036854775807
minBuyCost = [INF] * N
ret = -INF
for i in range(N):
ret = max(ret, AS[i] - minBuyCost[i])
m = min(minBuyCost[i], AS[i])
for j in edges[i]:
minBuyCost[j] = min(minBuyCost[j], m)
print(ret)
def blute(X, Y):
queue = {X}
ret = 0
while True:
newqueue = set()
if Y in queue:
return ret
ret += 1
for x in queue:
newqueue.add(x * 2)
newqueue.add(x + 1)
newqueue.add(x - 1)
queue = newqueue
def fulltest():
for x in range(20):
for y in range(20):
s = solve(x, y)
b = blute(x, y)
if s != b:
print(x, y, s, b)
ミスの原因「+1や-1の連続が最短経路のケースを取りこぼしてる」
下記コードの(1)のところ
「+1した後に+1することはない」は間違い。
その後に/2が来ることはないが、そのままゴールインすることはあり得た
python
def solve(X, Y):
from heapq import heappush, heappop
queue = [(0, Y)]
minCost = {Y: 0}
INF = 9223372036854775807
def add(cost, y):
c = minCost.get(y, INF)
if cost < c:
minCost[y] = cost
heappush(queue, (cost, y))
while True:
cost, y = heappop(queue)
if y == X:
return cost
if y < X:
add(cost + (X - y), X)
continue
if y == X + 1:
add(cost + 1, X)
continue
add(cost + (y - X), X) # (1)
if y % 2 == 0:
add(cost + 1, y // 2)
else:
add(cost + 2, (y + 1) // 2)
add(cost + 2, (y - 1) // 2)