結果

問題 No.707 書道
ユーザー nadare
提出日時 2018-06-29 23:04:02
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 541 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-07-01 00:09:29
合計ジャッジ時間 1,151 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
from math import sqrt

X = []
Y = []

H, W = map(int, input().split())

for h in range(1, H+1):
    for w, v in enumerate(map(int, input()), start=1):
        if v==0:
            continue
        X.append(w)
        Y.append(h)

rX = [0]*H + [W+1]*H + list(range(1, W+1)) + list(range(1, W+1))
rY = list(range(1, H+1)) + list(range(1, H+1)) + [0]*W + [H+1]*W

ans = 10**9

for rx, ry in zip(rX, rY):
    tmp = 0
    for x, y in zip(X, Y):
        tmp += sqrt((rx-x)**2 + (ry-y)**2)
    ans = min(tmp, ans)
print(ans)
0