結果

問題 No.31 悪のミックスジュース
ユーザー myuonmyuon
提出日時 2014-09-29 00:25:45
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 850 bytes
コンパイル時間 7,453 ms
コンパイル使用メモリ 162,484 KB
実行使用メモリ 803,128 KB
最終ジャッジ日時 2023-08-28 19:52:46
合計ジャッジ時間 8,391 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 MLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

import Control.Applicative
import qualified Data.IntMap as M
import Data.List
import Data.Array

solve n v cs = fst $ M.findMin $ M.filter (ordered . M.elems) $ M.fromList $ last' $ unfoldr next ([(sum cs, M.fromList $ zip [1..n] [1,1..])],0) where
  last' [] = [(sum cs, M.fromList $ zip [1..n] [1,1..])]
  last' xs = last xs
  
  cs' = listArray (1,n) cs

  ordered (y:[]) = True
  ordered (x:y:xs) = x >= y && ordered (y:xs)

  next (m,i)
    | i >= v - n = Nothing
    | otherwise = Just (m', (m',i+1))
    where
      m' = foldr go [] [1..n]
      go j m0 = foldr
        (\(k,a) b -> (k + cs' ! j, M.insertWith (+) j 1 a) : b) m0
        $ take 10 $ sort $ filter (ordered . M.elems . snd) m

main = do
  [n,v] <- fmap (read :: String -> Int) . words <$> getLine
  cs <- fmap (read :: String -> Int) . words <$> getLine
  print $ solve n v cs

0