結果
| 問題 | No.228 ゆきこちゃんの 15 パズル | 
| コンテスト | |
| ユーザー |  siman | 
| 提出日時 | 2016-03-25 03:42:19 | 
| 言語 | Ruby (3.4.1) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,372 bytes | 
| コンパイル時間 | 468 ms | 
| コンパイル使用メモリ | 7,168 KB | 
| 実行使用メモリ | 12,160 KB | 
| 最終ジャッジ日時 | 2024-10-02 00:41:50 | 
| 合計ジャッジ時間 | 2,663 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 11 WA * 6 | 
コンパイルメッセージ
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 |i|
      ny = y + DY[i]
      nx = x + DX[i]
      if is_inside?(ny,nx) && @current[ny][nx] != @field[ny][nx]
        return true
      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
            
            
            
        