結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー むらためむらため
提出日時 2019-01-23 19:28:10
言語 Nim
(2.0.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 915 bytes
コンパイル時間 621 ms
コンパイル使用メモリ 45,736 KB
最終ジャッジ日時 2023-09-14 02:37:58
合計ジャッジ時間 1,148 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
/home/judge/data/code/Main.nim(2, 21) Error: cannot open file: queues

ソースコード

diff #

import sequtils,algorithm,math,tables
import sets,intsets,queues,heapqueue,bitops,strutils
template times*(n:int,body) = (for _ in 0..<n: body)
template `max=`*(x,y) = x = max(x,y)
template `min=`*(x,y) = x = min(x,y)

proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': break
    result = 10 * result + k.ord - '0'.ord

var A = newSeqWith(16,scan())
const dist = toSeq(1..15) & 0
while true:
  if A == dist : quit "Yes",0
  if A[^1] == 0 : quit "No",0
  proc slide():bool =
    for i,a in A:
      if a != 0 : continue
      template impl(di:int,cond) =
        if i+di < A.len and cond and A[i+di] == dist[i] :
          swap(A[i],A[i+di])
          return true
      impl(1,i mod 4 != 3)
      impl(4,i<12)
      impl(-4,i>=4)
      impl(-1,i mod 4 != 0)
    return false
  if not slide() : quit "No",0
0