結果
| 問題 |
No.440 2次元チワワ問題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-10-29 14:25:09 |
| 言語 | Ruby (3.4.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,104 bytes |
| コンパイル時間 | 117 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 25,984 KB |
| 最終ジャッジ日時 | 2024-11-24 17:53:28 |
| 合計ジャッジ時間 | 105,593 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 TLE * 17 |
コンパイルメッセージ
Main.rb:3: warning: assigned but unused variable - w Syntax OK
ソースコード
def main
lines = STDIN.readlines
h, w = lines[0].split.map {|x| x.to_i}
s = []
h.times {|i| s << lines[i + 1].chomp}
q = lines[h + 1].chomp.to_i
q_array = []
q.times {|i| q_array << lines[h + i + 2].split.map {|x| x.to_i - 1}.to_a}
q_array.each do |a, b, c, d|
total = 0
a.upto(c) do |y|
b.upto(d) do |x|
if s[y][x] == "c"
total += search_w s, y, x, a, b, c, d
end
end
end
puts total
end
end
def search_w(s, y, x, a, b, c, d)
total = 0
total += search_w_dir s, y, x, -1, 0, a, b, c, d
total += search_w_dir s, y, x, 1, 0, a, b, c, d
total += search_w_dir s, y, x, 0, -1, a, b, c, d
total += search_w_dir s, y, x, 0, 1, a, b, c, d
total
end
def search_w_dir(s, y, x, j, i, a, b, c, d)
w_count = 0
while a <= y && y <= c && b <= x && x <= d
if s[y][x] == "w"
w_count += 1
end
y += j
x += i
end
w_count * (w_count - 1) / 2
end
main()