結果

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

ソースコード

diff #
raw source code

#!/usr/bin/env python3
import math
h, w = map(int, input().split())
p = [ list(map(int, input())) for _ in range(h) ]
pos = []
pos += [ (y, -1) for y in range(h) ]
pos += [ (y,  w) for y in range(h) ]
pos += [ (-1, x) for x in range(w) ]
pos += [ (h,  x) for x in range(w) ]
answer = math.inf
for y0, x0 in pos:
    acc = 0
    for y1 in range(h):
        for x1 in range(w):
            if p[y1][x1]:
                acc += math.hypot(x1 - x0, y1 - y0)
    answer = min(answer, acc)
print(answer)
0