結果

問題 No.13 囲みたい!
ユーザー aimyaimy
提出日時 2017-05-11 16:38:51
言語 Haskell
(9.8.2)
結果
TLE  
実行時間 -
コード長 611 bytes
コンパイル時間 1,809 ms
コンパイル使用メモリ 160,940 KB
実行使用メモリ 16,448 KB
最終ジャッジ日時 2023-10-13 11:03:28
合計ジャッジ時間 8,935 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,212 KB
testcase_01 AC 2 ms
7,064 KB
testcase_02 AC 2 ms
7,152 KB
testcase_03 AC 353 ms
12,292 KB
testcase_04 AC 22 ms
12,192 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Data.Bool
import Data.List

main = do
 [w,h] <- map read . words <$> getLine
 ms <- map read . words <$> getContents :: IO [Int]
 putStrLn (bool "impossible" "possible" (anyClosed w h ms))

anyClosed w h ms = or (unfoldr (isClosed w) ims)
 where ims = zip [i | i<-[1..(w+1)*h], mod i (w+1) /= 0] ms

isClosed w [] = Nothing
isClosed w ((i,m):ims) = Just (dfs w [i,i] is, ims)
 where is = map fst (filter ((==m) . snd) ((i,m):ims))

dfs w acc@(a:a':as) is
 | null is = False
 | notElem a is = False
 | elem a as = True
 | otherwise = or (map (\i -> dfs w (i:acc) is) (delete a' [a-1,a+1,a-(w+1),a+(w+1)]))
0