結果
| 問題 |
No.85 TVザッピング(1)
|
| コンテスト | |
| ユーザー |
suppy193
|
| 提出日時 | 2016-10-27 14:09:00 |
| 言語 | Ruby (3.4.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 934 bytes |
| コンパイル時間 | 229 ms |
| コンパイル使用メモリ | 7,680 KB |
| 実行使用メモリ | 86,912 KB |
| 最終ジャッジ日時 | 2024-11-24 04:54:56 |
| 合計ジャッジ時間 | 23,611 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 WA * 1 RE * 7 TLE * 3 |
コンパイルメッセージ
Main.rb:23: warning: assigned but unused variable - ch Syntax OK
ソースコード
input = gets.strip.split(' ').map(&:to_i)
@n = input[0]
@m = input[1]
@c = input[2]
@remocon = []
(1..@n * @m).each do |i|
@remocon << i
end
x = (@c - 1) % @m + 1
y = (@c - 1) / @m + 1
#print "#{@c} : #{x},#{y}\n"
#x = 1
#y = 3
#p x + (y - 1) * @m
def dfs(pos, path)
#p pos
#p path
x = pos[0]
y = pos[1]
ch = x + (y - 1) * @m
[[1, 0], [0, -1], [-1, 0], [0, 1]].each do |dir|
dx = dir[0]
dy = dir[1]
next_x = x + dx
next_y = y + dy
next if next_x < 1 || next_x > @m || next_y < 1 || next_y > @n
next_pos = [next_x, next_y]
next_ch = next_x + (next_y - 1) * @m
#print "#{pos} -> #{next_pos}\n"
#print "#{ch} -> #{next_ch}\n"
#next if path.include?(next_pos)
next if path.include?(next_ch)
#p path
#path << next_pos
#p path + [next_ch]
if (path + [next_ch]).length == @n * @m
puts "YES"
exit
end
dfs(next_pos, path + [next_ch])
end
end
path = []
dfs([x, y], path.clone)
puts "NO"
suppy193