結果

問題 No.429 CupShuffle
ユーザー ducktailducktail
提出日時 2018-08-20 21:20:38
言語 Haskell
(9.8.2)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 1,304 bytes
コンパイル時間 6,489 ms
コンパイル使用メモリ 198,044 KB
実行使用メモリ 38,904 KB
最終ジャッジ日時 2023-08-18 07:32:46
合計ジャッジ時間 8,134 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,756 KB
testcase_01 AC 2 ms
6,960 KB
testcase_02 AC 3 ms
7,064 KB
testcase_03 AC 3 ms
6,980 KB
testcase_04 AC 3 ms
7,580 KB
testcase_05 AC 2 ms
6,964 KB
testcase_06 AC 4 ms
7,688 KB
testcase_07 AC 3 ms
7,740 KB
testcase_08 AC 3 ms
6,996 KB
testcase_09 AC 4 ms
7,696 KB
testcase_10 AC 12 ms
13,144 KB
testcase_11 AC 102 ms
38,904 KB
testcase_12 AC 83 ms
35,380 KB
testcase_13 AC 103 ms
38,796 KB
testcase_14 AC 93 ms
36,288 KB
testcase_15 AC 3 ms
7,032 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
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')
0