結果
| 問題 |
No.86 TVザッピング(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-12-05 00:32:40 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,484 bytes |
| コンパイル時間 | 191 ms |
| コンパイル使用メモリ | 8,228 KB |
| 実行使用メモリ | 13,312 KB |
| 最終ジャッジ日時 | 2025-06-20 13:56:59 |
| 合計ジャッジ時間 | 3,833 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 29 WA * 1 |
コンパイルメッセージ
Main.rb:89: warning: '+' after local variable or literal is interpreted as binary operator even though it seems like unary operator Main.rb:91: warning: '+' after local variable or literal is interpreted as binary operator even though it seems like unary operator Main.rb:93: warning: '+' after local variable or literal is interpreted as binary operator even though it seems like unary operator Main.rb:63: warning: assigned but unused variable - start_found Syntax OK
ソースコード
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 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