結果
問題 | No.707 書道 |
ユーザー |
![]() |
提出日時 | 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 = 0P.each.with_index(1) do |row, y|row.each.with_index(1) do |c, x|next if c == '0'dy = y - cydx = x - cxdist += Math.sqrt(dy ** 2 + dx ** 2)endenddistendmin_dist = Float::INFINITY0.upto(W + 1) do |x|0.upto(H + 1) do |y|next if 1 <= y && y <= H && 1 <= x && x <= Wnext if y == 0 && x == 0next if y == 0 && x == W + 1next if y == H + 1 && x == 0next if y == H + 1 && x == W + 1dist = f(x, y)if min_dist > distmin_dist = distendendendputs "%.12f" % min_dist