結果

問題 No.429 CupShuffle
ユーザー ducktailducktail
提出日時 2018-06-02 23:29:42
言語 Haskell
(9.8.2)
結果
TLE  
実行時間 -
コード長 1,123 bytes
コンパイル時間 1,901 ms
コンパイル使用メモリ 160,676 KB
実行使用メモリ 11,452 KB
最終ジャッジ日時 2023-09-12 21:41:10
合計ジャッジ時間 5,982 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
11,452 KB
testcase_01 AC 3 ms
7,092 KB
testcase_02 AC 2 ms
7,168 KB
testcase_03 AC 3 ms
7,104 KB
testcase_04 AC 7 ms
11,348 KB
testcase_05 AC 3 ms
7,060 KB
testcase_06 AC 12 ms
11,392 KB
testcase_07 AC 12 ms
11,424 KB
testcase_08 AC 3 ms
7,168 KB
testcase_09 AC 7 ms
11,332 KB
testcase_10 TLE -
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 Control.Applicative ((<$>), (<*>))
import Control.Monad (replicateM)
import Data.List (foldl', intercalate)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List (unfoldr)
import Data.Char (isSpace)

main :: IO ()
main = do
  [n, k, x] <- f
  solve n <$> replicateM (x-1) f <*> (getLine >> replicateM (k-x) f) <*> f >>= putStrLn
  where f = readil B.readInt <$> B.getLine
  
solve :: Int -> [[Int]] -> [[Int]] -> [Int] -> String
solve n hs ts cs = intercalate " " . map show . foldr g [] $ zip3 [1..n] nhs nts
  where swp ls ss = foldl' f ls ss
          where f ls [i, j] = let (us, (v:vs)) = splitAt (i-1) ls
                                  (vs', (w:ws)) = splitAt (j-i-1) vs
                              in us ++ (w:vs') ++ (v:ws)
        nhs = swp [1..n] hs
        nts = swp cs (reverse ts)
        g (i, x, y) ls | x == y = ls
                       | otherwise = i:ls

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr g
  where
    g s = do
      (n, s') <- f s
      return (n, B.dropWhile isSpace s')
0