結果

問題 No.490 yukiソート
ユーザー atuk721atuk721
提出日時 2017-05-06 03:38:17
言語 Haskell
(9.8.2)
結果
TLE  
実行時間 -
コード長 661 bytes
コンパイル時間 3,536 ms
コンパイル使用メモリ 159,876 KB
実行使用メモリ 15,928 KB
最終ジャッジ日時 2023-10-12 13:16:56
合計ジャッジ時間 12,020 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,852 KB
testcase_01 AC 3 ms
6,792 KB
testcase_02 AC 3 ms
6,968 KB
testcase_03 AC 2 ms
6,928 KB
testcase_04 AC 412 ms
11,484 KB
testcase_05 AC 422 ms
11,456 KB
testcase_06 AC 422 ms
11,444 KB
testcase_07 AC 412 ms
11,524 KB
testcase_08 AC 421 ms
11,504 KB
testcase_09 AC 422 ms
11,512 KB
testcase_10 AC 423 ms
11,484 KB
testcase_11 AC 432 ms
12,156 KB
testcase_12 AC 422 ms
11,432 KB
testcase_13 AC 422 ms
11,468 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 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

0