結果

問題 No.707 書道
ユーザー rlangevinrlangevin
提出日時 2023-01-15 01:35:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 555 bytes
コンパイル時間 454 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 77,144 KB
最終ジャッジ日時 2023-08-27 05:31:19
合計ジャッジ時間 2,304 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,256 KB
testcase_01 AC 75 ms
71,444 KB
testcase_02 AC 89 ms
76,988 KB
testcase_03 AC 73 ms
71,700 KB
testcase_04 AC 75 ms
71,380 KB
testcase_05 AC 93 ms
77,144 KB
testcase_06 AC 100 ms
77,116 KB
testcase_07 AC 101 ms
77,140 KB
testcase_08 AC 78 ms
76,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import *

def dist(x1, y1, x2, y2):
    return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
    

H, W = map(int, input().split())
P = []
for i in range(H):
    L = list(input())
    L = list(map(int, L))
    P.append(L)
    
T = []
for i in range(W):
    T.append((-1, i))
    T.append((H, i))
for i in range(H):
    T.append((i, -1))
    T.append((i, W))
    
ans = 10 ** 18
for x, y in T:
    val = 0
    for i in range(H):
        for j in range(W):
            if P[i][j]:
                val += dist(x, y, i, j)
    ans = min(ans, val)
print(ans)
0