結果

問題 No.85 TVザッピング(1)
ユーザー suppy193suppy193
提出日時 2016-10-27 14:09:00
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 934 bytes
コンパイル時間 378 ms
コンパイル使用メモリ 11,472 KB
実行使用メモリ 81,264 KB
最終ジャッジ日時 2023-08-15 20:21:21
合計ジャッジ時間 7,803 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
15,104 KB
testcase_01 AC 70 ms
15,180 KB
testcase_02 AC 73 ms
16,760 KB
testcase_03 AC 72 ms
15,808 KB
testcase_04 RE -
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:23: warning: assigned but unused variable - ch
Syntax OK

ソースコード

diff #

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"
0