結果

問題 No.490 yukiソート
ユーザー atuk721
提出日時 2017-05-06 04:24:15
言語 Haskell
(9.10.1)
結果
TLE  
実行時間 -
コード長 753 bytes
コンパイル時間 5,128 ms
コンパイル使用メモリ 171,520 KB
実行使用メモリ 167,552 KB
最終ジャッジ日時 2024-09-14 12:31:25
合計ジャッジ時間 12,113 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 2
other AC * 14 TLE * 1 -- * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
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

ソースコード

diff #

main :: IO ()
main = do
  n <- readLn
  is <- map read . words <$> getLine
  let result = yukisort n 1 (comb n) is
  putStrLn . unwords . map show $ result

yukisort :: Int -> Int -> [(Int, Int)] -> [Int] -> [Int]
yukisort n i c xs
  | i >= 2 * n - 3 = xs
  | otherwise = yukisort n (i + 1) c $ foldl (\a v -> proc v a) xs (comb' c)
  where comb' = filter (\(p, q) -> p + q == i)
        proc (p, q) ys | ys !! p > ys !! q = swap p q ys
                       | otherwise = ys

comb :: Int -> [(Int, Int)]
comb n = [(p, q) | p <- [0..n - 1], q <- [0..n - 1], p < q]

swap :: Int -> Int -> [Int] -> [Int]
swap i j as@(x:xs)
  | i == 0 || j == 0 = let m = max i j in as !! m : take (m - 1) xs ++ x : drop m xs
  | otherwise = x : swap (i - 1) (j - 1) xs

0