結果

問題 No.157 2つの空洞
ユーザー finefine
提出日時 2016-03-04 20:16:35
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 808 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 11,916 KB
実行使用メモリ 16,092 KB
最終ジャッジ日時 2023-10-24 19:49:44
合計ジャッジ時間 2,626 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
16,092 KB
testcase_01 AC 79 ms
16,092 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 78 ms
16,092 KB
testcase_06 WA -
testcase_07 AC 78 ms
16,092 KB
testcase_08 AC 79 ms
16,088 KB
testcase_09 AC 78 ms
16,092 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 79 ms
16,092 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 80 ms
16,092 KB
testcase_18 WA -
testcase_19 AC 79 ms
16,092 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

@w,@h = gets.split.map(&:to_i)
@data = STDIN.map(&:chomp).join('').split('')

def sol now,d,f,memo
    tmp = 0
    if @data[now] == '.'
        if f == 1
            return 0
        end
    else
        tmp = f = 1
    end
    ans = 10000
    memo[now] = true
    if d != 'S' && now < @w && !memo[now - @w] 
        ans = [ans,sol(now - @w,'N',f,memo) + tmp].min
    end
    if d != 'N' && now / @w != @h - 1 && !memo[now + @w]
        ans = [ans,sol(now + @w,'S',f,memo) + tmp].min
    end
    if d != 'E' && now % @w != 0 && !memo[now - 1]
        ans = [ans,sol(now - 1,'W',f,memo) + tmp].min
    end
    if d != 'W' && now % @w != @w - 1 && !memo[now + 1]
        ans = [ans,sol(now + 1,'E',f,memo) + tmp].min
    end
    return ans
end

memo = Array.new(@w * @h,false)
p sol(@data.index('.'),'',0,memo)
0