제출 #1148086

#제출 시각아이디문제언어결과실행 시간메모리
1148086walkerCoin Collecting (JOI19_ho_t4)Pypy 3
100 / 100
253 ms104348 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()

컴파일 시 표준 출력 (stdout) 메시지

Compiling 'joi2019_ho_t4.py'...

=======
  adding: __main__.pyc (deflated 46%)

=======
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...