結果
問題 | No.397 NO MORE KADOMATSU |
ユーザー |
|
提出日時 | 2018-07-06 15:16:55 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 56 ms / 2,000 ms |
コード長 | 1,128 bytes |
コンパイル時間 | 6,684 ms |
コンパイル使用メモリ | 204,308 KB |
実行使用メモリ | 25,476 KB |
平均クエリ数 | 936.56 |
最終ジャッジ日時 | 2024-07-17 01:47:55 |
合計ジャッジ時間 | 8,280 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 |
コンパイルメッセージ
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 Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import System.IO (hFlush, stdout) import Data.List (foldl') import Data.Char (isSpace) import Data.Vector (Vector, (!), (//)) import qualified Data.Vector as V main :: IO () main = do n <- readi B.readInt <$> B.getLine solve n <$> readiv B.readInt <$> B.getLine >>= mapM putStrLn hFlush stdout B.getLine return () solve :: Int -> Vector Int -> [String] solve n v = show (length rs) : (reverse rs) where ids = [(j, j+1) | i <- [n-2, n-3 .. 0], j <- [0 .. i]] f (tv, rs) (i, j) | (tv ! i) <= (tv ! j) = (tv, rs) | otherwise = (tv // [(i, tv ! j), (j, tv ! i)], unwords [show i, show j] : rs) (_, rs) = foldl' f (v, []) ids readi :: Integral a => (ByteString -> Maybe (a, ByteString)) -> ByteString -> a readi f s = let Just (n, _) = f s in n 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')