結果

問題 No.707 書道
ユーザー MineMine
提出日時 2020-09-15 23:11:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 180 ms / 2,000 ms
コード長 607 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 10,800 KB
実行使用メモリ 8,956 KB
最終ジャッジ日時 2023-09-04 03:06:07
合計ジャッジ時間 1,400 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,824 KB
testcase_01 AC 20 ms
8,748 KB
testcase_02 AC 49 ms
8,820 KB
testcase_03 AC 20 ms
8,560 KB
testcase_04 AC 19 ms
8,568 KB
testcase_05 AC 97 ms
8,848 KB
testcase_06 AC 139 ms
8,956 KB
testcase_07 AC 180 ms
8,844 KB
testcase_08 AC 22 ms
8,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
h, w = map(int, input().split())
p = [input() for i in range(h)]
black = []
for i in range(h):
    for g in range(w):
        if p[i][g] == "1":
            black.append((i+1, g+1))

red = defaultdict(float)
for i in range(1, h+1):
    for x, y in black:
        red[(i, 0)] += ((x-i)**2 + (y)**2)**0.5
        red[(i, w+1)] += ((x-i)**2 + (y-w-1)**2)**0.5


for i in range(1, w+1):
    for x, y in black:
        red[(0, i)] += ((x)**2 + (y-i)**2)**0.5
        red[(h+1, i)] += ((x-h-1)**2 + (y-i)**2)**0.5

if red == {}:
    print(0)
else:
    print(min(red.values()))
0