結果

問題 No.707 書道
ユーザー nadarenadare
提出日時 2018-06-29 23:04:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 541 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 11,004 KB
実行使用メモリ 7,992 KB
最終ジャッジ日時 2023-09-13 15:34:08
合計ジャッジ時間 1,159 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,960 KB
testcase_01 AC 16 ms
7,956 KB
testcase_02 AC 34 ms
7,976 KB
testcase_03 AC 15 ms
7,952 KB
testcase_04 AC 16 ms
7,876 KB
testcase_05 AC 64 ms
7,876 KB
testcase_06 AC 85 ms
7,988 KB
testcase_07 AC 112 ms
7,992 KB
testcase_08 AC 18 ms
7,940 KB
権限があれば一括ダウンロードができます

ソースコード

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