結果

問題 No.286 Modulo Discount Store
コンテスト
ユーザー aimy
提出日時 2017-05-12 20:56:16
言語 Haskell
(9.14.1)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 689 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,177 ms
コンパイル使用メモリ 164,096 KB
最終ジャッジ日時 2026-04-04 19:18:26
合計ジャッジ時間 1,592 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge5_1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.14.1/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.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.8’.
    Use -v to see a list of the files searched for.
  |
2 | import qualified Data.IntMap as M
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ソースコード

diff #
raw source code

import Data.IntMap ((!))
import qualified Data.IntMap as M
import Control.Monad
import Data.Bits

main = do
 n <- readLn
 ms <- map read . words <$> getContents
 print (mds n ms)

mds n ms = snd $ M.findMax $ foldr (dp n ms) (M.singleton 0 0) (replicate n [0..n-1])

dp n ms ds im = M.unionsWith min $ (im:) $ map buy ds
 where
  buy d = M.mapKeysMonotonic (flip setBit d) $ M.mapWithKey (\k v -> v + (max 0 ((ms!!d) - (table!k)))) $
          M.filterWithKey (\k _ -> not (testBit k d)) im
  
  table = M.fromDistinctAscList $ do
   bs <- replicateM n [0,1]
   let k = sum (zipWith (*) (reverse bs) (map bit [0..n]))
   let v = sum (zipWith (*) (reverse bs) ms) `mod` 1000
   return (k,v)
0