結果

問題 No.86 TVザッピング(2)
ユーザー Tsuneo YoshiokaTsuneo Yoshioka
提出日時 2014-12-05 00:16:29
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 2,364 bytes
コンパイル時間 248 ms
コンパイル使用メモリ 11,496 KB
実行使用メモリ 15,536 KB
最終ジャッジ日時 2023-09-02 08:43:04
合計ジャッジ時間 4,554 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
15,076 KB
testcase_01 AC 88 ms
15,052 KB
testcase_02 AC 89 ms
15,048 KB
testcase_03 AC 94 ms
15,316 KB
testcase_04 AC 89 ms
15,168 KB
testcase_05 AC 92 ms
15,340 KB
testcase_06 AC 90 ms
15,280 KB
testcase_07 AC 87 ms
15,048 KB
testcase_08 AC 93 ms
15,484 KB
testcase_09 AC 92 ms
15,500 KB
testcase_10 AC 90 ms
15,536 KB
testcase_11 AC 87 ms
15,056 KB
testcase_12 AC 88 ms
15,332 KB
testcase_13 AC 86 ms
15,076 KB
testcase_14 AC 90 ms
15,444 KB
testcase_15 AC 86 ms
15,248 KB
testcase_16 AC 89 ms
15,388 KB
testcase_17 WA -
testcase_18 AC 89 ms
15,228 KB
testcase_19 AC 87 ms
15,136 KB
testcase_20 AC 87 ms
15,140 KB
testcase_21 AC 94 ms
15,380 KB
testcase_22 AC 86 ms
15,164 KB
testcase_23 AC 94 ms
15,492 KB
testcase_24 AC 89 ms
15,172 KB
testcase_25 AC 87 ms
15,292 KB
testcase_26 AC 87 ms
15,368 KB
testcase_27 AC 88 ms
15,160 KB
testcase_28 AC 90 ms
15,284 KB
testcase_29 RE -
testcase_30 AC 87 ms
15,140 KB
testcase_31 AC 87 ms
15,052 KB
testcase_32 AC 89 ms
15,052 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:80: warning: `+' after local variable or literal is interpreted as binary operator
Main.rb:80: warning: even though it seems like unary operator
Main.rb:82: warning: `+' after local variable or literal is interpreted as binary operator
Main.rb:82: warning: even though it seems like unary operator
Main.rb:84: warning: `+' after local variable or literal is interpreted as binary operator
Main.rb:84: warning: even though it seems like unary operator
Main.rb:54: warning: assigned but unused variable - start_found
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)
mp = []
mp << "#" + "#" * M + "#"
while($_=gets) do
    $_.chomp!
    #puts "1_=#{$_}"
    $_ = "#" + $_ + "#"
    #puts "2_=#{$_}"
    mp << $_
end
mp << "#" + "#" * M + "#"
#puts mp.to_s
start_x = nil
start_y = nil

(1...N+1).each{|n|
    (1...M+1).each{|m|
        #puts "mp[#{n}][#{m}]=#{m[n][m]}"
        if(mp[n][m]=='.') then
            start_y = n
            start_x = m;
            break
        end
    }
    if start_x then
        break
    end
}
cur_x = start_x
cur_y = start_y

directions = [[0,1],[1,0],[0,-1],[-1,0]]
cur_d = nil
(0...directions.size).each{|d|
    #puts "pre:d=#{d}, cur_x=#{cur_x}, cur_y=#{cur_y}"
    #puts "mp[cur_y+#{directions[d][1]}][cur_x+#{directions[d][0]}]"
    #puts "mp[#{cur_y+directions[d][1]}][#{cur_x+directions[d][0]}]"
    if(mp[cur_y+directions[d][1]][cur_x+directions[d][0]]=='.')then
        cur_d = start_d = d
        cur_x += d[0]
        cur_y += d[0]
        break
    end
}
start2_x = cur_x
start2_y = cur_y

init = true
used_right=false
while true
    #puts "cur_d=#{cur_d}, cur_x=#{cur_x}, cur_y=#{cur_y}"

    if cur_x == start_x && cur_y == start_y then
        start_found = true
    end
    if cur_x == start2_x && cur_y == start2_y then
        if ! init
            mp[cur_y][cur_x] = '*'
            ok = true
            (1...N+1).each{|n|
                (1...M+1).each{|m|
                    #puts "mp[#{n}][#{m}]=#{mp[n][m]}"
                    if(mp[n][m]=='.')
                        ok = false
                    end
                }
            }
            
            if ok
                puts "YES"
            else
                puts "NO"
            end
            exit 0
        end
        init = false
    else
        mp[cur_y][cur_x] = '*'
    end
    if mp[cur_y+directions[cur_d][1]][cur_x +directions[cur_d][0]] == '.'
        #
    elsif mp[cur_y+directions[(cur_d+1)%4][1]][cur_x +directions[(cur_d+1)%4][0]] == '.'
        cur_d = (cur_d+1)%4
    elsif used_right == false && mp[cur_y+directions[(cur_d+3)%4][1]][cur_x +directions[(cur_d+3)%4][0]] == '.'
        cur_d = (cur_d+3)%4
        used_right = true
    else
        puts "NO"
        exit 0
    end
    cur_x += directions[cur_d][0]
    cur_y += directions[cur_d][1]
end


0