結果

問題 No.707 書道
コンテスト
ユーザー _polarbear08
提出日時 2018-08-03 05:38:52
言語 Python3
(3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 94 ms / 2,000 ms
+ 917µs
コード長 762 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 71 ms
コンパイル使用メモリ 15,232 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2026-10-14 15:38:50
合計ジャッジ時間 1,628 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from math import sqrt

def sum_dist(H: int, W: int, st: tuple) -> int:
    global P
    dist = 0
    for w in range(1,W+1):
        for h in range(1,H+1):
            if P[h-1][w-1] == 1:
                dist += sqrt((st[0]-w)**2 + (st[1]-h)**2)
     
    return dist           

H,W = map(int, input().split())
P = []
for i in range(H):
    P.append([int(p) for p in list(input().rstrip())])
    

INF = float("inf")
ans = INF

for w in range(1,W+1):
    ans_temp = sum_dist(H,W,(w,0))
    ans = min(ans, ans_temp)
    ans_temp = sum_dist(H,W,(w,H+1))
    ans = min(ans, ans_temp)
    
for h in range(1,H+1):
    ans_temp = sum_dist(H,W,(0,h))
    ans = min(ans, ans_temp)
    ans_temp = sum_dist(H,W,(W+1,h))
    ans = min(ans, ans_temp)
    
print(ans)
      
0