結果
問題 | No.490 yukiソート |
ユーザー | ducktail |
提出日時 | 2018-04-11 16:43:49 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 1,295 bytes |
コンパイル時間 | 10,879 ms |
コンパイル使用メモリ | 202,960 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-26 21:12:30 |
合計ジャッジ時間 | 7,842 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 34 |
コンパイルメッセージ
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 (forM_, when) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.Char (isSpace) import Data.Vector (Vector, (!)) import qualified Data.Vector as V import Data.Vector.Mutable (IOVector) import qualified Data.Vector.Mutable as VM main :: IO () main = do n <- readLn v <- getl (readiv B.readInt) solve n v solve :: Int -> Vector Int -> IO () solve n v = do mv <- V.thaw v yukisort n mv printVector n mv getl :: (ByteString -> a) -> IO a getl f = f <$> B.getLine readiv :: Integral a => (ByteString -> Maybe (a, ByteString)) -> ByteString -> Vector a readiv f = V.unfoldr g where g s = do (n, s') <- f s return (n, B.dropWhile isSpace s') yukisort :: (Ord a, Eq a) => Int -> IOVector a -> IO () yukisort n mv = do forM_ [1 .. 2*n-4] $ \i -> do forM_ [0 .. i `div` 2] $ \p -> do let q = i - p when (p < q && q <= n - 1) $ do pa <- VM.read mv p qa <- VM.read mv q when (pa > qa) $ do VM.swap mv p q printVector :: Show a => Int -> IOVector a -> IO () printVector n mv = do forM_ [0..n-1] $ \i -> do x <- VM.read mv i if i /= 0 then putStr (" " ++ (show x)) else putStr (show x) putStrLn ""