結果

問題 No.326 あみだますたー
コンテスト
ユーザー aimy
提出日時 2017-04-24 23:16:37
言語 Haskell
(9.14.1)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 737 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,524 ms
コンパイル使用メモリ 196,864 KB
実行使用メモリ 12,800 KB
最終ジャッジ日時 2026-04-04 05:06:47
合計ジャッジ時間 5,650 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2
other AC * 5 WA * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.14.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
Main.hs:10:20: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘head’
    (imported from Prelude, but defined in GHC.Internal.List):
    "This is a partial function, it throws an error on empty lists. Use pattern matching, 'Data.List.uncons' or 'Data.Maybe.listToMaybe' instead. Consider refactoring to use "Data.List.NonEmpty"."
   |
10 |  is <- map (read . head . words) <$> replicateM k getLine
   |                    ^^^^

Main.hs:23:17: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘head’
    (imported from Prelude, but defined in GHC.Internal.List):
    "This is a partial function, it throws an error on empty lists. Use pattern matching, 'Data.List.uncons' or 'Data.Maybe.listToMaybe' instead. Consider refactoring to use "Data.List.NonEmpty"."
   |
23 |  let xi = fst $ head $ dropWhile (uncurry (==)) $ zip goal xs
   |                 ^^^^

[2 of 2] Linking a.out

ソースコード

diff #
raw source code

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] (map pred 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