結果

問題 No.440 2次元チワワ問題
コンテスト
ユーザー tana_twtr
提出日時 2016-10-29 18:55:50
言語 Ruby
(4.0.2)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
WA  
実行時間 -
コード長 1,033 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 193 ms
コンパイル使用メモリ 8,832 KB
実行使用メモリ 14,976 KB
最終ジャッジ日時 2026-05-18 20:11:57
合計ジャッジ時間 10,264 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 8 TLE * 1 -- * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:3: warning: assigned but unused variable - w
Syntax OK

ソースコード

diff #
raw source code

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|
        
        result = 0
        
        a.upto(c) do |y|
            c_count = 0
            b.upto(d) do |x|
                
                if s[y][x] == "c"
                    c_count += 1
                end
                
            end
            w_count = d - b + 1 - c_count
            result += w_count * (w_count - 1) / 2 * c_count
        end
        
        b.upto(d) do |x|
            c_count = 0
            a.upto(c) do |y|
                
                if s[y][x] == "c"
                    c_count += 1
                end

            end
            w_count = c - a + 1 - c_count
            result += w_count * (w_count - 1) / 2 * c_count
        end
        
        puts result

    end
end

main()

0