結果

問題 No.707 書道
ユーザー nonokai10nonokai10
提出日時 2018-09-30 17:11:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 563 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-20 13:42:13
合計ジャッジ時間 1,060 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
10,880 KB
testcase_01 AC 29 ms
10,880 KB
testcase_02 AC 42 ms
11,008 KB
testcase_03 AC 27 ms
11,008 KB
testcase_04 AC 31 ms
10,880 KB
testcase_05 AC 62 ms
11,008 KB
testcase_06 AC 78 ms
11,008 KB
testcase_07 AC 104 ms
11,136 KB
testcase_08 AC 27 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
h, w = map(int, input().split())
p = [list(map(int, list(input().strip()))) for i in range(h)]
c = []
for i in range(h):
    for j in range(w):
        if p[i][j] == 1:
            c.append((i+1,j+1))
cost = []
for i in range(1,h+1):
    cost.append(sum([math.sqrt((x-i)**2 + y**2) for x, y in c]))
    cost.append(sum([math.sqrt((x-i)**2 + (y-(w+1))**2) for x, y in c]))

for i in range(1,w+1):
    cost.append(sum([math.sqrt(x**2 + (y-i)**2) for x, y in c]))
    cost.append(sum([math.sqrt((x-(h+1))**2 + (y-i)**2) for x, y in c]))

print(min(cost))
0