結果

問題 No.490 yukiソート
ユーザー aimyaimy
提出日時 2017-06-20 17:35:25
言語 Haskell
(9.8.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 498 bytes
コンパイル時間 116 ms
コンパイル使用メモリ 150,016 KB
最終ジャッジ日時 2024-04-27 02:26:53
合計ジャッジ時間 520 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )

Main.hs:1:1: error: [GHC-87110]
    Could not load module ‘Data.IntMap’.
    It is a member of the hidden package ‘containers-0.6.8’.
    Use -v to see a list of the files searched for.
  |
1 | import Data.IntMap ((!))
  | ^^^^^^^^^^^^^^^^^^^^^^^^

Main.hs:2:1: error: [GHC-87110]
    Could not load module ‘Data.IntMap’.
    It is a member of the hidden package ‘containers-0.6.8’.
    Use -v to see a list of the files searched for.
  |
2 | import qualified Data.IntMap as M
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ソースコード

diff #

import Data.IntMap ((!))
import qualified Data.IntMap as M
import Data.List

swap i j im = M.insert j (im!i) (M.insert i (im!j) im)

main = do
 n <- readLn
 as <- map read . words <$> getLine :: IO [Int]
 let ias = M.fromList (zip [0..n-1] as)
 putStrLn $ unwords $ map show (yukisort n ias)

yukisort n ias = M.elems $ foldl' ys ias [1..2*n-4]
 where
  ys acc i = foldr swappq acc [(p,q) | p<-[0 .. n-1], let q = i-p, q>0, q<n, p<q]
  swappq (p,q) acc = if acc!p > acc!q then swap p q acc else acc
0