結果

問題 No.2897 2集合間距離
ユーザー tassei903tassei903
提出日時 2024-09-20 22:12:06
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 984 bytes
コンパイル時間 770 ms
コンパイル使用メモリ 82,364 KB
実行使用メモリ 136,600 KB
最終ジャッジ日時 2024-09-20 22:12:16
合計ジャッジ時間 5,230 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,480 KB
testcase_01 AC 36 ms
51,840 KB
testcase_02 AC 37 ms
52,736 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #


import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
######################################################################


inf = float('inf')
    
H = W = 5
n = ni()
p = [na() for _ in range(n)]
p = [(x+1, y+1) for x, y in p]
m = ni()
q = [na() for _ in range(m)]
q = [(x+1, y+1) for x, y in q]

ans = inf

for _ in range(4):
    p = [(H - 1 - y, x) for x, y in p]
    q = [(H - 1 - y, x) for x, y in q]

    A = [[-inf]*(W+1) for _ in range(H+1)]

    for x, y in p:
        A[x][y] = x + y
    
    for i in range(H):
        for j in range(W):
            A[i+1][j+1] = max(A[i+1][j+1], A[i][j+1], A[i+1][j])

    # for i in range(H):
    #     print(*A[i])
    # print()

    for x, y in q:
        ans = min(ans, x + y - A[x][y])
    

print(ans)
0