結果
問題 | No.707 書道 |
ユーザー | siman |
提出日時 | 2022-10-07 08:06:03 |
言語 | Ruby (3.3.0) |
結果 |
AC
|
実行時間 | 216 ms / 2,000 ms |
コード長 | 657 bytes |
コンパイル時間 | 262 ms |
コンパイル使用メモリ | 11,476 KB |
実行使用メモリ | 15,620 KB |
最終ジャッジ日時 | 2023-09-02 09:26:17 |
合計ジャッジ時間 | 2,816 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 80 ms
15,084 KB |
testcase_01 | AC | 81 ms
15,192 KB |
testcase_02 | AC | 111 ms
15,144 KB |
testcase_03 | AC | 79 ms
15,380 KB |
testcase_04 | AC | 80 ms
15,088 KB |
testcase_05 | AC | 146 ms
15,620 KB |
testcase_06 | AC | 180 ms
15,520 KB |
testcase_07 | AC | 216 ms
15,400 KB |
testcase_08 | AC | 84 ms
15,208 KB |
コンパイルメッセージ
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