| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1148086 | walker | Coin Collecting (JOI19_ho_t4) | Pypy 3 | 253 ms | 104348 KiB |
import sys
n = 0
mat = []
ans = 0
def balancing():
global n, mat, ans
num1 = 0
num2 = 0
for i in range(1, n + 1):
num1 += (mat[i][1] - 1)
num2 += (mat[i][2] - 1)
while num1 > 0 and num2 < 0:
num1 -= 1
num2 += 1
ans += 1
while num1 < 0 and num2 > 0:
num1 += 1
num2 -= 1
ans += 1
ans += abs(num1) + abs(num2)
def main():
global n, mat, ans
data = sys.stdin.read().split()
if not data:
return
n = int(data[0])
ans = 0
mat = [[0, 0, 0] for _ in range(n + 1)]
total_coins = 2 * n
index = 1
for _ in range(total_coins):
x = int(data[index])
y = int(data[index + 1])
index += 2
if x < 1:
if y >= 2:
mat[1][2] += 1
ans += abs(x - 1) + abs(y - 2)
else:
mat[1][1] += 1
ans += abs(x - 1) + abs(y - 1)
elif 1 <= x <= n:
if y >= 2:
ans += abs(y - 2)
mat[x][2] += 1
else:
ans += abs(y - 1)
mat[x][1] += 1
elif x > n:
if y >= 2:
mat[n][2] += 1
ans += abs(x - n) + abs(y - 2)
else:
mat[n][1] += 1
ans += abs(x - n) + abs(y - 1)
balancing()
sys.stdout.write(str(ans))
main()Compilation message (stdout)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
