結果

問題 No.440 2次元チワワ問題
ユーザー tana_twtr
提出日時 2016-10-29 13:29:33
言語 Ruby
(3.4.1)
結果
RE  
実行時間 -
コード長 975 bytes
コンパイル時間 51 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-11-24 17:47:55
合計ジャッジ時間 5,275 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other RE * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:2: warning: assigned but unused variable - w
Syntax OK

ソースコード

diff #

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}.to_a}

def search_w(y, x, a, b, c, d)
    
   total = 0
   total += search_w_dir y, x, -1, 0, a, b, c, d
   total += search_w_dir y, x, 1, 0, a, b, c, d
   total += search_w_dir y, x, 0, -1, a, b, c, d
   total += search_w_dir y, x, 0, 1, a, b, c, d
   total

end

def search_w_dir(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

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 y, x, a, b, c, d
            end
        end
    end
    
    puts total

end

0