結果

問題 No.707 書道
ユーザー _polarbear08_polarbear08
提出日時 2018-08-03 05:38:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 803 bytes
コンパイル時間 146 ms
コンパイル使用メモリ 12,016 KB
実行使用メモリ 10,176 KB
最終ジャッジ日時 2023-10-19 21:16:24
合計ジャッジ時間 1,042 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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           

file = open("sampleyukico707.txt", "r")

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