結果
| 問題 |
No.707 書道
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2022-10-07 08:06:03 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 205 ms / 2,000 ms |
| コード長 | 657 bytes |
| コンパイル時間 | 214 ms |
| コンパイル使用メモリ | 7,680 KB |
| 実行使用メモリ | 12,800 KB |
| 最終ジャッジ日時 | 2024-06-11 16:13:01 |
| 合計ジャッジ時間 | 1,983 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 |
コンパイルメッセージ
Syntax OK
ソースコード
H, W = gets.split.map(&:to_i)
P = H.times.map { gets.chomp.chars }
def f(cx, cy)
dist = 0
P.each.with_index(1) do |row, y|
row.each.with_index(1) do |c, x|
next if c == '0'
dy = y - cy
dx = x - cx
dist += Math.sqrt(dy ** 2 + dx ** 2)
end
end
dist
end
min_dist = Float::INFINITY
0.upto(W + 1) do |x|
0.upto(H + 1) do |y|
next if 1 <= y && y <= H && 1 <= x && x <= W
next if y == 0 && x == 0
next if y == 0 && x == W + 1
next if y == H + 1 && x == 0
next if y == H + 1 && x == W + 1
dist = f(x, y)
if min_dist > dist
min_dist = dist
end
end
end
puts "%.12f" % min_dist
siman