結果

問題 No.596 郵便配達
ユーザー gew1fw
提出日時 2025-06-12 15:42:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,088 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 82,512 KB
実行使用メモリ 183,408 KB
最終ジャッジ日時 2025-06-12 15:42:47
合計ジャッジ時間 3,507 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    ptr = 0
    N = int(input[ptr])
    ptr += 1
    M = int(input[ptr])
    ptr += 1

    min_x = float('inf')
    max_x = -float('inf')
    min_y = float('inf')
    max_y = -float('inf')

    for _ in range(M):
        x_i = int(input[ptr])
        ptr += 1
        d_i = int(input[ptr])
        ptr += 1

        if x_i < min_x:
            min_x = x_i
        if x_i > max_x:
            max_x = x_i

        for __ in range(d_i):
            y_j = int(input[ptr])
            ptr += 1
            if y_j < min_y:
                min_y = y_j
            if y_j > max_y:
                max_y = y_j

    # Calculate the total distance
    part1 = max_x - min_x
    part2 = max_y - min_y

    # Compute the minimal connection between the two parts
    connections = [
        abs(max_x - min_y),
        abs(max_x - max_y),
        abs(min_x - min_y),
        abs(min_x - max_y)
    ]
    min_connection = min(connections)

    total = part1 + part2 + min_connection
    print(total)

if __name__ == "__main__":
    main()
0