結果

問題 No.247 線形計画問題もどき
ユーザー h_nosonh_noson
提出日時 2015-07-18 00:50:04
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 571 bytes
コンパイル時間 4,698 ms
コンパイル使用メモリ 165,132 KB
実行使用メモリ 11,252 KB
最終ジャッジ日時 2023-09-22 18:46:33
合計ジャッジ時間 6,136 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,564 KB
testcase_01 AC 2 ms
7,040 KB
testcase_02 AC 3 ms
7,704 KB
testcase_03 AC 2 ms
7,092 KB
testcase_04 AC 2 ms
7,072 KB
testcase_05 AC 2 ms
7,036 KB
testcase_06 AC 3 ms
6,968 KB
testcase_07 AC 3 ms
7,180 KB
testcase_08 AC 6 ms
10,968 KB
testcase_09 AC 3 ms
6,948 KB
testcase_10 AC 3 ms
6,928 KB
testcase_11 AC 2 ms
7,064 KB
testcase_12 AC 3 ms
7,036 KB
testcase_13 AC 2 ms
7,092 KB
testcase_14 AC 2 ms
7,084 KB
testcase_15 AC 3 ms
7,088 KB
testcase_16 AC 3 ms
7,012 KB
testcase_17 AC 12 ms
11,136 KB
testcase_18 AC 3 ms
7,112 KB
testcase_19 AC 12 ms
11,192 KB
testcase_20 AC 12 ms
11,252 KB
testcase_21 AC 4 ms
7,752 KB
testcase_22 AC 4 ms
7,828 KB
testcase_23 AC 3 ms
7,572 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 3 ms
7,320 KB
testcase_27 AC 3 ms
7,372 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 Control.Applicative
import Control.Monad
import Data.List

solve :: Int -> [Int] -> Int
solve c ai = case f c (sortBy (flip compare) ai) 0 of
                 [] -> -1
                 list -> minimum . take 100 $ list
    where
        f 0 _ ans = return ans
        f _ [] _ = []
        f rest (x:xs) ans = do
            let m = rest `div` x
            i <- [m,m-1..0]
            f (rest - i*x) xs (ans + i)

main :: IO ()
main = do
    c <- readLn :: IO Int
    n <- readLn :: IO Int
    ai <- map read . words <$> getLine :: IO [Int]
    print $ solve c ai
0