結果

問題 No.326 あみだますたー
ユーザー aimyaimy
提出日時 2017-04-24 23:05:39
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 726 bytes
コンパイル時間 1,373 ms
コンパイル使用メモリ 158,284 KB
実行使用メモリ 13,968 KB
最終ジャッジ日時 2023-10-11 13:27:10
合計ジャッジ時間 6,257 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,000 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 3 ms
7,592 KB
testcase_06 WA -
testcase_07 AC 12 ms
11,676 KB
testcase_08 AC 32 ms
11,768 KB
testcase_09 WA -
testcase_10 AC 42 ms
13,168 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 Control.Monad
import Data.List (foldl', findIndex, unfoldr)

replace i xs = xs1 ++ (xj : xi : xs2)
 where (xs1,(xi:xj:xs2)) = splitAt (i-2) xs

main = do
 n <- readLn
 k <- readLn
 is <- map (read . head . words) <$> replicateM k getLine
 goal <- map read . words <$> getLine
 let start = amida [1..n] is
 let inss = unfoldr (insert goal) start
 print (length inss)
 putStr $ (unlines . map (unwords . map show)) inss

amida :: [Int] -> [Int] -> [Int]
amida xs = foldl' (flip replace) xs

insert :: [Int] -> [Int] -> Maybe ([Int],[Int])
insert goal xs = do
 guard (goal /= xs)
 let xi = fst $ head $ dropWhile (uncurry (==)) $ zip goal xs
 i <- succ <$> findIndex (==xi) xs 
 let ji = [i-1,i]
 return (ji, replace i xs)
0