結果

問題 No.247 線形計画問題もどき
ユーザー h_nosonh_noson
提出日時 2015-07-18 00:20:48
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 528 bytes
コンパイル時間 7,797 ms
コンパイル使用メモリ 162,384 KB
実行使用メモリ 8,108 KB
最終ジャッジ日時 2023-09-22 18:39:17
合計ジャッジ時間 9,420 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
7,048 KB
testcase_02 AC 3 ms
7,436 KB
testcase_03 AC 2 ms
7,088 KB
testcase_04 AC 3 ms
7,052 KB
testcase_05 AC 3 ms
7,100 KB
testcase_06 AC 3 ms
7,064 KB
testcase_07 AC 2 ms
7,076 KB
testcase_08 AC 3 ms
7,032 KB
testcase_09 AC 3 ms
6,956 KB
testcase_10 AC 2 ms
7,000 KB
testcase_11 AC 3 ms
7,120 KB
testcase_12 AC 2 ms
7,008 KB
testcase_13 AC 2 ms
7,172 KB
testcase_14 AC 2 ms
7,140 KB
testcase_15 AC 2 ms
7,172 KB
testcase_16 AC 3 ms
6,980 KB
testcase_17 WA -
testcase_18 AC 3 ms
7,240 KB
testcase_19 AC 3 ms
7,984 KB
testcase_20 WA -
testcase_21 AC 3 ms
7,700 KB
testcase_22 WA -
testcase_23 AC 3 ms
7,552 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 3 ms
7,248 KB
testcase_27 AC 3 ms
7,388 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 = head $ f c (sortBy (flip compare) ai) 0 ++ [-1]
    where
        f rest [] ans = do
            guard (rest == 0)
            return ans
        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