Break through in 1 minute. Just write.
x = int(input())
if x >= 0:
print(x)
else:
print(0)
Postscript: I thought I usually wrote max (x, 0)
.
x = int(input())
print(max(x, 0))
Break through in 5 and a half minutes. This kind of mathematical thing is hard ...
Sx, Sy, Gx, Gy = map(int, input().split())
print(Sx + (Gx - Sx) * Sy / (Sy + Gy))
It breaks through in 5 and a half minutes. N ≤ 8, so if you try all the patterns, it's OK. But I don't feel like I can solve it without itertools.permutations
....
from itertools import permutations
N, K = map(int, input().split())
T = [list(map(int, input().split())) for _ in range(N)]
result = 0
for p in permutations(range(1, N)):
i = 0
t = 0
for x in p:
t += T[i][x]
i = x
t += T[i][0]
if t == K:
result += 1
print(result)
Break through in 5 minutes. One shot of the imos method.
from itertools import accumulate
N, W = map(int, input().split())
t = [0] * (2 * 10 ** 5 + 1)
for _ in range(N):
S, T, P = map(int, input().split())
t[S] += P
t[T] -= P
if all(x <= W for x in accumulate(t)):
print('Yes')
else:
print('No')
I couldn't break through. I didn't understand the subscript expression of the array at a glance, so I fixed it and leaked AC a little later. I should have made it a compile error without inserting it, failure.
I wondered if it could be calculated only with a two-dimensional array to write the result, but if I do it naive, it will be * O * (* HW * (* H * + * W *)), so it is useless, and it is relaxed using SegmentTree. The amount of calculation does not decrease unless the position of the nearest stone is known by * O * (1), so it was concluded that one accumulator in the left, upper, and upper left directions is needed. After that, you can fill the result array with the number according to the method of moving to it by raster scan.
If you think about it, you didn't need the result array. Below is the code that goes through PyPy.
m = 1000000007
H, W = map(int, input().split())
S = [input() for _ in range(H)]
au = [0] * W #Upward accumulator
aul = [0] * (H + W - 1) #Upper left accumulator
for h in range(H):
al = 0 #Left accumulator
for w in range(W):
n = h - w + (W - 1)
if h == 0 and w == 0:
al = 1
au[w] = 1
aul[n] = 1
elif S[h][w] == '#':
al = 0
au[w] = 0
aul[n] = 0
else:
t = al + au[w] + aul[n]
al += t
al %= m
au[w] += t
au[w] %= m
aul[n] += t
aul[n] %= m
print(t % m)
Recommended Posts