結果
| 問題 | No.228 ゆきこちゃんの 15 パズル | 
| コンテスト | |
| ユーザー |  aimy | 
| 提出日時 | 2017-09-03 15:07:21 | 
| 言語 | Haskell (9.10.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 564 bytes | 
| コンパイル時間 | 5,155 ms | 
| コンパイル使用メモリ | 174,464 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-06 20:03:16 | 
| 合計ジャッジ時間 | 2,606 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 17 | 
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking a.out
ソースコード
import Data.Bool
import Data.List
main = getContents >>= putStrLn . bool "No" "Yes" . pazzle15 . map read . words
pazzle15 ns = null $ snd $ until (\(x,_) -> x==16) move (s, ds)
  where
    (_,s) = maybe undefined id $ find ((==0) . fst) nis
    ds = filter (\(x,y) -> neighbor x y) nis
    nis = zip ns [1..16]
move (x,ds) = case find ((==x) . fst) ds of
  Nothing -> (16, (0,0) : ds)
  Just (x,y) -> (y, delete (x,y) ds)
neighbor x y = (qx==qy && abs (x-y) == 1) || (rx==ry && abs (x-y) == 4)
  where
    (qx,rx) = divMod (x-1) 4
    (qy,ry) = divMod (y-1) 4
            
            
            
        