結果
問題 |
No.429 CupShuffle
|
ユーザー |
|
提出日時 | 2018-08-20 21:20:38 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 78 ms / 2,000 ms |
コード長 | 1,304 bytes |
コンパイル時間 | 11,394 ms |
コンパイル使用メモリ | 200,064 KB |
実行使用メモリ | 34,944 KB |
最終ジャッジ日時 | 2024-11-27 11:14:27 |
合計ジャッジ時間 | 12,326 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
コンパイルメッセージ
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 Control.Applicative import Control.Monad import Control.Monad.ST import Data.List import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.Char (isSpace) import Data.Vector.Unboxed (Vector, (!)) import qualified Data.Vector.Unboxed as V import Data.Vector.Unboxed.Mutable (IOVector, STVector) import qualified Data.Vector.Unboxed.Mutable as VM main :: IO () main = do [n, k, x] <- f solve n <$> replicateM (x-1) f <*> (B.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 = runST $ do hv <- V.thaw $ V.fromList [1..n] :: ST s (STVector s Int) forM_ hs $ \[a,b] -> do VM.swap hv (a-1) (b-1) tv <- V.thaw $ V.fromList cs :: ST s (STVector s Int) forM_ (reverse ts) $ \[a,b] -> do VM.swap tv (a-1) (b-1) xs <- foldM (f hv tv) [] [n,n-1 .. 1] return . unwords . map show $ xs where f hv tv ls i = do x <- VM.read hv (i-1) y <- VM.read tv (i-1) if x == y then return ls else return (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')