結果

問題 No.397 NO MORE KADOMATSU
ユーザー ducktailducktail
提出日時 2018-07-06 15:16:55
言語 Haskell
(9.8.2)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 1,128 bytes
コンパイル時間 3,603 ms
コンパイル使用メモリ 198,264 KB
実行使用メモリ 27,644 KB
平均クエリ数 936.56
最終ジャッジ日時 2023-09-24 01:49:21
合計ジャッジ時間 5,798 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
23,892 KB
testcase_01 AC 26 ms
23,640 KB
testcase_02 AC 27 ms
24,000 KB
testcase_03 AC 30 ms
23,908 KB
testcase_04 AC 26 ms
23,844 KB
testcase_05 AC 27 ms
23,796 KB
testcase_06 AC 30 ms
25,108 KB
testcase_07 AC 30 ms
25,544 KB
testcase_08 AC 26 ms
24,048 KB
testcase_09 AC 26 ms
23,904 KB
testcase_10 AC 56 ms
27,644 KB
testcase_11 AC 26 ms
23,372 KB
testcase_12 AC 46 ms
27,256 KB
testcase_13 AC 45 ms
27,236 KB
testcase_14 AC 45 ms
27,360 KB
testcase_15 AC 45 ms
27,248 KB
testcase_16 AC 26 ms
23,856 KB
testcase_17 AC 26 ms
23,400 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 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')
0