結果
問題 | No.228 ゆきこちゃんの 15 パズル |
ユーザー |
![]() |
提出日時 | 2016-03-25 03:43:55 |
言語 | Ruby (3.4.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,343 bytes |
コンパイル時間 | 58 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 12,416 KB |
最終ジャッジ日時 | 2024-10-02 00:41:53 |
合計ジャッジ時間 | 2,512 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 WA * 3 |
コンパイルメッセージ
Syntax OK
ソースコード
class Yukicoder attr_accessor :check_field DY = [-1, 0, 0, 1] DX = [ 0,-1, 1, 0] def initialize @field = [ [ 1, 2, 3, 4], [ 5, 6, 7, 8], [ 9,10,11,12], [13,14,15, 0] ] @check_field = Array.new(4){ Array.new(4, false) } @current = [] 4.times do |y| list = gets.chomp.split.map(&:to_i) @current << list if list.index(0) @curY = y @curX = list.index(0) end end loop do check_field[@curY][@curX] = true if check puts "Yes" break end unless move puts "No" break end end end def move 4.times do |i| ny = @curY + DY[i] nx = @curX + DX[i] if is_inside?(ny,nx) && !check_field[ny][nx] && @current[ny][nx] != @field[ny][nx] @current[@curY][@curX], @current[ny][nx] = @current[ny][nx], @current[@curY][@curX] @curY = ny @curX = nx return true end end false end def exist_diff?(y, x) 4.times do |y| 4.times do |x| if @current[y][x] != @field[y][x] return true end end end false end def check @curY == 3 && @curX == 3 && !exist_diff?(@curY, @curX) end def is_inside?(y, x) 0 <= y && y < 4 && 0 <= x && x < 4 end end Yukicoder.new