結果

問題 No.86 TVザッピング(2)
ユーザー Tsuneo YoshiokaTsuneo Yoshioka
提出日時 2014-12-05 00:34:26
言語 Ruby
(3.3.0)
結果
AC  
実行時間 98 ms / 5,000 ms
コード長 2,484 bytes
コンパイル時間 58 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-06-07 10:25:09
合計ジャッジ時間 4,229 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
12,288 KB
testcase_01 AC 91 ms
12,416 KB
testcase_02 AC 91 ms
12,288 KB
testcase_03 AC 91 ms
12,288 KB
testcase_04 AC 92 ms
12,288 KB
testcase_05 AC 92 ms
12,416 KB
testcase_06 AC 90 ms
12,160 KB
testcase_07 AC 90 ms
12,416 KB
testcase_08 AC 98 ms
12,288 KB
testcase_09 AC 97 ms
12,416 KB
testcase_10 AC 98 ms
12,288 KB
testcase_11 AC 90 ms
12,160 KB
testcase_12 AC 90 ms
12,416 KB
testcase_13 AC 91 ms
12,288 KB
testcase_14 AC 97 ms
12,544 KB
testcase_15 AC 91 ms
12,416 KB
testcase_16 AC 93 ms
12,288 KB
testcase_17 AC 93 ms
12,160 KB
testcase_18 AC 90 ms
12,288 KB
testcase_19 AC 92 ms
12,160 KB
testcase_20 AC 91 ms
12,288 KB
testcase_21 AC 97 ms
12,288 KB
testcase_22 AC 90 ms
12,288 KB
testcase_23 AC 96 ms
12,288 KB
testcase_24 AC 90 ms
12,416 KB
testcase_25 AC 91 ms
12,288 KB
testcase_26 AC 89 ms
12,288 KB
testcase_27 AC 90 ms
12,288 KB
testcase_28 AC 90 ms
12,160 KB
testcase_29 AC 89 ms
12,160 KB
testcase_30 AC 91 ms
12,288 KB
testcase_31 AC 91 ms
12,288 KB
testcase_32 AC 90 ms
12,160 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:89: warning: `+' after local variable or literal is interpreted as binary operator
Main.rb:89: warning: even though it seems like unary operator
Main.rb:92: warning: `+' after local variable or literal is interpreted as binary operator
Main.rb:92: warning: even though it seems like unary operator
Main.rb:94: warning: `+' after local variable or literal is interpreted as binary operator
Main.rb:94: warning: even though it seems like unary operator
Main.rb:63: 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
if cur_x == nil
    puts "NO"
    exit
end

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 += directions[d][0]
        cur_y += directions[d][1]
        break
    end
}
if cur_d == nil
    puts "NO"
    exit
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 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
    elsif 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
    else
        puts "NO"
        exit 0
    end
    cur_x += directions[cur_d][0]
    cur_y += directions[cur_d][1]
end


0