結果

問題 No.490 yukiソート
ユーザー atuk721atuk721
提出日時 2017-05-06 04:24:15
言語 Haskell
(9.8.2)
結果
TLE  
実行時間 -
コード長 753 bytes
コンパイル時間 1,139 ms
コンパイル使用メモリ 161,280 KB
実行使用メモリ 169,444 KB
最終ジャッジ日時 2023-10-12 13:32:36
合計ジャッジ時間 8,090 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,776 KB
testcase_01 AC 2 ms
6,864 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 2 ms
6,904 KB
testcase_04 AC 302 ms
15,156 KB
testcase_05 AC 292 ms
15,164 KB
testcase_06 AC 312 ms
15,056 KB
testcase_07 AC 303 ms
15,176 KB
testcase_08 AC 303 ms
15,072 KB
testcase_09 AC 312 ms
15,192 KB
testcase_10 AC 312 ms
15,176 KB
testcase_11 AC 322 ms
15,056 KB
testcase_12 AC 312 ms
15,060 KB
testcase_13 AC 313 ms
15,120 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

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