結果
問題 | No.527 ナップサック容量問題 |
ユーザー | aimy |
提出日時 | 2017-06-09 23:32:58 |
言語 | Haskell (9.8.2) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 617 bytes |
コンパイル時間 | 308 ms |
コンパイル使用メモリ | 142,664 KB |
最終ジャッジ日時 | 2023-10-24 02:23:04 |
合計ジャッジ時間 | 768 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) Main.hs:1:1: error: Could not load module ‘Data.IntMap’ It is a member of the hidden package ‘containers-0.6.7’. You can run ‘:set -package containers’ to expose it. (Note: this unloads all the modules in the current scope.) Use -v (or `:set -v` in ghci) to see a list of the files searched for. | 1 | import Data.IntMap ((!)) | ^^^^^^^^^^^^^^^^^^^^^^^^ Main.hs:2:1: error: Could not load module ‘Data.IntMap.Strict’ It is a member of the hidden package ‘containers-0.6.7’. You can run ‘:set -package containers’ to expose it. (Note: this unloads all the modules in the current scope.) Use -v (or `:set -v` in ghci) to see a list of the files searched for. | 2 | import qualified Data.IntMap.Strict as M | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ソースコード
import Data.IntMap ((!)) import qualified Data.IntMap.Strict as M import Data.List import Control.Monad main = do n <- readLn vws <- map (map read . words) <$> replicateM n getLine v <- readLn mapM_ (putStrLn . maybe "inf" show) (knap v vws) knap vmax vws = [max 1 <$> rmin, rmax] where rs = M.keys (M.filter (==vmax) im') rs' = M.keys (M.filter (>vmax) im') im' = foldl' dp (M.singleton 0 0) vws dp im [v,w] = M.filter (<=vmax+1000) $ M.unionWith max im $ M.mapKeys (+w) $ M.map (+v) im rmin = Just (head rs) rmax = if null rs' || (sum (map head vws) <= vmax) then Nothing else Just (head rs' - 1)