結果
| 問題 |
No.228 ゆきこちゃんの 15 パズル
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-06-20 00:27:11 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 80 ms / 5,000 ms |
| コード長 | 1,004 bytes |
| コンパイル時間 | 76 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 12,288 KB |
| 最終ジャッジ日時 | 2024-07-07 04:30:25 |
| 合計ジャッジ時間 | 2,241 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
コンパイルメッセージ
Main.rb:2: warning: assigned but unused variable - cur_y Syntax OK
ソースコード
@target=STDIN.read.split("\n").map{|l| l.split.map(&:to_i);}
cur_y=nil,cur_x=nil
(0...4).each{|r|
(0...4).each{|c|
if @target[r][c]==0
cur_y = r
cur_x = c
end
}
}
@ma=Array.new(4).map{Array.new(4)}
(0..15).each{|i|
@ma[i/4][i%4]=i+1
}
@ma[3][3]=0
@used=Array.new(16,false)
def go(cur_y, cur_x)
#puts "cur_y=#{cur_y}, cur_x=#{cur_x}"
#puts "ma=#{@ma}"
if @ma==@target
puts "Yes"
exit 0
end
dx=[0,1,0,-1];
dy=[1,0,-1,0];
(0...4).each{|i|
y2=cur_y+dy[i]
x2=cur_x+dx[i]
if(y2<0 || y2>3)
next
end
if(x2<0 || x2>3)
next
end
if(@used[@ma[y2][x2]]==true)
next
end
@used[@ma[y2][x2]]=true
@ma[cur_y][cur_x],@ma[y2][x2] = @ma[y2][x2],@ma[cur_y][cur_x]
go(y2,x2)
@ma[cur_y][cur_x],@ma[y2][x2] = @ma[y2][x2],@ma[cur_y][cur_x]
@used[@ma[y2][x2]]=false
}
end
go(3,3)
puts "No"