結果
| 問題 |
No.707 書道
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 21:19:47 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 50 ms / 2,000 ms |
| コード長 | 1,022 bytes |
| コンパイル時間 | 290 ms |
| コンパイル使用メモリ | 82,444 KB |
| 実行使用メモリ | 72,664 KB |
| 最終ジャッジ日時 | 2025-03-20 21:20:42 |
| 合計ジャッジ時間 | 951 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 |
ソースコード
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))
lam6er