結果

問題 No.707 書道
ユーザー kimiyukikimiyuki
提出日時 2018-06-29 23:41:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 498 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 8,068 KB
最終ジャッジ日時 2023-09-13 15:46:44
合計ジャッジ時間 1,134 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,924 KB
testcase_01 AC 17 ms
8,012 KB
testcase_02 AC 42 ms
8,068 KB
testcase_03 AC 15 ms
7,952 KB
testcase_04 AC 15 ms
8,024 KB
testcase_05 AC 80 ms
7,884 KB
testcase_06 AC 111 ms
7,988 KB
testcase_07 AC 142 ms
8,016 KB
testcase_08 AC 18 ms
7,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import math
h, w = map(int, input().split())
p = [ list(map(int, input())) for _ in range(h) ]
pos = []
pos += [ (y, -1) for y in range(h) ]
pos += [ (y,  w) for y in range(h) ]
pos += [ (-1, x) for x in range(w) ]
pos += [ (h,  x) for x in range(w) ]
answer = math.inf
for y0, x0 in pos:
    acc = 0
    for y1 in range(h):
        for x1 in range(w):
            if p[y1][x1]:
                acc += math.hypot(x1 - x0, y1 - y0)
    answer = min(answer, acc)
print(answer)
0