結果

問題 No.707 書道
ユーザー lam6er
提出日時 2025-03-20 19:00:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,022 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 82,184 KB
実行使用メモリ 72,600 KB
最終ジャッジ日時 2025-03-20 19:01:23
合計ジャッジ時間 1,166 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

H, W = map(int, input().split())
dots = []

for y in range(1, H + 1):
    line = input().strip()
    for x in range(1, W + 1):
        if line[x - 1] == '1':
            dots.append((x, y))

if not dots:
    print("0.00000000")
else:
    min_total = float('inf')
    positions = []

    # Left edge: x=0, y from 1 to H
    for y in range(1, H + 1):
        positions.append((0, y))
    
    # Right edge: x=W+1, y from 1 to H
    for y in range(1, H + 1):
        positions.append((W + 1, y))
    
    # Top edge: y=0, x from 1 to W
    for x in range(1, W + 1):
        positions.append((x, 0))
    
    # Bottom edge: y=H+1, x from 1 to W
    for x in range(1, W + 1):
        positions.append((x, H + 1))

    for (sx, sy) in positions:
        total = 0.0
        for (x, y) in dots:
            dx = sx - x
            dy = sy - y
            dist = math.sqrt(dx ** 2 + dy ** 2)
            total += dist
        if total < min_total:
            min_total = total

    print("{0:.8f}".format(min_total))
0