結果
| 問題 |
No.228 ゆきこちゃんの 15 パズル
|
| コンテスト | |
| ユーザー |
小指が強い人
|
| 提出日時 | 2015-11-16 18:48:53 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 90 ms / 5,000 ms |
| コード長 | 937 bytes |
| コンパイル時間 | 237 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 12,288 KB |
| 最終ジャッジ日時 | 2024-12-26 04:09:51 |
| 合計ジャッジ時間 | 2,644 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
コンパイルメッセージ
Syntax OK
ソースコード
N = 4
$a = Array.new(N)
$b = Array.new(N).map{ Array.new(N, true) }
$dx = [1, 0, -1, 0]
$dy = [0, 1, 0, -1]
def process(cx, cy, n)
if n == 0
return true
end
v = cy * N + cx + 1
4.times do |i|
x = cx + $dx[i]
y = cy + $dy[i]
if x < 0 || x >= N || y < 0 || y >= N
next
elsif !$b[y][x]
next
elsif v != $a[y][x]
next
end
$b[y][x] = false
if process(x, y, n - 1)
return true
end
$b[y][x] = true
end
return false
end
fx = 0
fy = 0
n = 0
N.times do |i|
$a[i] = gets.split.map(&:to_i)
N.times do |j|
if $a[i][j] == i * N + j + 1
$b[i][j] = false
elsif $a[i][j] == 0
fx = j
fy = i
$b[i][j] = false
else
n += 1
end
end
end
if process(fx, fy, n)
puts "Yes"
else
puts "No"
end
小指が強い人