結果

問題 No.707 書道
ユーザー letrangerjpletrangerjp
提出日時 2018-06-29 22:37:26
言語 Ruby
(3.2.2)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 406 bytes
コンパイル時間 61 ms
コンパイル使用メモリ 11,424 KB
実行使用メモリ 15,668 KB
最終ジャッジ日時 2023-09-13 15:25:58
合計ジャッジ時間 1,759 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,556 KB
testcase_01 AC 81 ms
15,580 KB
testcase_02 AC 101 ms
15,660 KB
testcase_03 AC 81 ms
15,292 KB
testcase_04 AC 81 ms
15,140 KB
testcase_05 AC 133 ms
15,500 KB
testcase_06 AC 159 ms
15,660 KB
testcase_07 AC 190 ms
15,668 KB
testcase_08 AC 83 ms
15,648 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

H, W = gets.split.map &:to_i
$board = $<.map{|s|s.to_i(2)}

def f(a, b)
  (a**2 + b**2) ** 0.5
end

def g(yy, xx)
  sum = 0
  H.times{|y|
    W.times{|x|
      next if $board[y][x] != 1
      sum += f(xx - x, yy - y)
    }
  }
  sum
end

ans = 1.0/0
(0...H).each{|yy|
  [-1, W].each{|xx|
    ans = [ans, g(yy, xx)].min
  }
}
(0...W).each{|xx|
  [-1, H].each{|yy|
    ans = [ans, g(yy, xx)].min
  }
}
p ans
0