Break through in 4 minutes. Just write. Is the ARC A problem so easy?
X, Y = map(int, input().split())
def f(n):
if n == 3:
return 100000
elif n == 2:
return 200000
elif n == 1:
return 300000
else:
return 0
result = f(X) + f(Y)
if X == 1 and Y == 1:
result += 400000
print(result)
Break through in 26 minutes. 1 WA.
Assuming that the position of the cut is p and the length of the bar is l, if p is to the left of the center, it is the difference in length to the left.(l - p) - p = l -Add 2p or l on the right-Need to reduce 2p.Similarly, if p is to the right of the middle, then 2p to the right-l Add or 2p on the left-l need to reduce.After all|2p - l|It becomes the cost of, and it is sufficient to find the required cost at all breaks and take the minimum value..
N = int(input())
A = list(map(int, input().split()))
a = A[:-1]
for i in range(1, N - 1):
a[i] += a[i - 1]
l = sum(A)
print(min(abs(p + p - l) for p in a))
I didn't calculate everything at first, but I wrote to calculate the middle two, so I ate WA .... There is no problem in terms of computational complexity, so I should have calculated everything obediently.
Could not break through. AC. 12 and a half minutes after the end.
The policy is to start with strawberries, expand the area to the left, top, and right unless they hit each other, and copy the top to the last remaining part.
H, W, K = map(int, input().split())
s = [input() for _ in range(H)]
a = [[-1] * W for _ in range(H)]
sbs = []
n = 1
for i in range(H):
si = s[i]
for j in range(W):
if si[j] == '#':
a[i][j] = n
n += 1
sbs.append((i, j))
for sb in sbs:
i, j = sb
n = a[i][j]
t, l = i - 1, j - 1
r = j + 1
while t > -1:
if a[t][j] != -1:
break
t -= 1
t += 1
while l > -1:
if a[i][l] != -1:
break
l -= 1
l += 1
while r < W:
if a[i][r] != -1:
break
r += 1
r -= 1
for y in range(t, i + 1):
ay = a[y]
for x in range(l, r + 1):
ay[x] = n
for h in range(H - 1, -1, -1):
if a[h][0] != -1:
break
h += 1
for i in range(h, H):
ai1 = a[i - 1]
ai = a[i]
for j in range(W):
ai[j] = ai1[j]
for i in range(H):
print(*a[i])
Recommended Posts