結果

問題 No.707 書道
ユーザー ssmkzkssmkzk
提出日時 2019-06-20 17:35:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 800 bytes
コンパイル時間 572 ms
コンパイル使用メモリ 10,752 KB
実行使用メモリ 8,416 KB
最終ジャッジ日時 2023-08-22 19:41:32
合計ジャッジ時間 1,369 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,128 KB
testcase_01 AC 17 ms
8,336 KB
testcase_02 AC 49 ms
8,372 KB
testcase_03 AC 16 ms
8,296 KB
testcase_04 AC 16 ms
8,336 KB
testcase_05 AC 104 ms
8,352 KB
testcase_06 AC 149 ms
8,268 KB
testcase_07 AC 197 ms
8,416 KB
testcase_08 AC 21 ms
8,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

H, W = map(int, input().split())
l = []
for i in range(H):
    ll = ["0"] + list(input()) + ["0"]
    l.append(ll)
l = [["0" for i in range(W + 2)]] + l + [["0" for i in range(W + 2)]]

best_ans = 10000000000
for i in range(H + 2):
    for j in range(W + 2):
        if 0 < i < H + 1 and 0 < j < W + 1:
            continue
        if i == j == 0:
            continue
        if i == 0 and j == W + 1:
            continue
        if j == 0 and i == H + 1:
            continue
        if i == H + 1 and j == W + 1:
            continue
        ans = 0
        for cki in range(H + 2):
            for ckj in range(W + 2):
                if l[cki][ckj] == "1":
                    ans += math.sqrt(pow(i - cki,2) + pow(j - ckj,2)) 
        best_ans = min(best_ans,ans)

print(best_ans)
0