結果
| 問題 |
No.490 yukiソート
|
| コンテスト | |
| ユーザー |
atuk721
|
| 提出日時 | 2017-05-06 03:38:17 |
| 言語 | Haskell (9.10.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 661 bytes |
| コンパイル時間 | 7,570 ms |
| コンパイル使用メモリ | 173,184 KB |
| 実行使用メモリ | 13,824 KB |
| 最終ジャッジ日時 | 2024-09-14 12:16:33 |
| 合計ジャッジ時間 | 15,678 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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
ソースコード
main :: IO ()
main = do
n <- readLn
is <- map read . words <$> getLine
let result = yukisort n 1 is
putStrLn . unwords . map show $ result
yukisort :: Int -> Int -> [Int] -> [Int]
yukisort n i xs
| i >= 2 * n - 3 = xs
| otherwise = yukisort n (i + 1) $ foldl (\a v -> proc v a) xs comb
where comb = [(p, q) | p <- [0..n - 1], q <- [0..n - 1], p < q, p + q == i]
proc (p, q) ys | ys !! p > ys !! q = swap p q ys
| otherwise = ys
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
atuk721