結果

問題 No.286 Modulo Discount Store
ユーザー aimyaimy
提出日時 2017-05-12 20:42:46
言語 Haskell
(9.8.2)
結果
AC  
実行時間 1,783 ms / 2,000 ms
コード長 683 bytes
コンパイル時間 7,419 ms
コンパイル使用メモリ 163,116 KB
実行使用メモリ 307,776 KB
最終ジャッジ日時 2023-10-13 13:58:40
合計ジャッジ時間 10,996 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,664 KB
testcase_01 AC 5 ms
10,640 KB
testcase_02 AC 273 ms
69,120 KB
testcase_03 AC 3 ms
8,096 KB
testcase_04 AC 4 ms
8,796 KB
testcase_05 AC 3 ms
7,652 KB
testcase_06 AC 712 ms
149,080 KB
testcase_07 AC 2 ms
7,532 KB
testcase_08 AC 2 ms
7,644 KB
testcase_09 AC 3 ms
7,696 KB
testcase_10 AC 93 ms
28,244 KB
testcase_11 AC 3 ms
8,036 KB
testcase_12 AC 3 ms
8,016 KB
testcase_13 AC 273 ms
69,216 KB
testcase_14 AC 2 ms
7,660 KB
testcase_15 AC 2 ms
7,636 KB
testcase_16 AC 5 ms
10,552 KB
testcase_17 AC 1,783 ms
307,776 KB
testcase_18 AC 93 ms
28,252 KB
testcase_19 AC 2 ms
7,632 KB
testcase_20 AC 22 ms
15,704 KB
testcase_21 AC 3 ms
7,796 KB
testcase_22 AC 3 ms
7,748 KB
testcase_23 AC 273 ms
69,212 KB
testcase_24 AC 3 ms
7,848 KB
testcase_25 AC 42 ms
19,004 KB
testcase_26 AC 3 ms
7,580 KB
testcase_27 AC 42 ms
19,024 KB
testcase_28 AC 723 ms
149,088 KB
testcase_29 AC 3 ms
7,668 KB
testcase_30 AC 3 ms
7,684 KB
testcase_31 AC 12 ms
12,428 KB
testcase_32 AC 12 ms
12,364 KB
testcase_33 AC 3 ms
7,800 KB
testcase_34 AC 3 ms
7,860 KB
testcase_35 AC 6 ms
10,540 KB
testcase_36 AC 2 ms
7,636 KB
testcase_37 AC 42 ms
18,908 KB
testcase_38 AC 3 ms
7,604 KB
testcase_39 AC 713 ms
149,080 KB
testcase_40 AC 3 ms
7,624 KB
testcase_41 AC 2 ms
7,664 KB
testcase_42 AC 2 ms
7,752 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 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.mapKeys (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