Submission #3783929


Source Code Expand

import Control.Monad.State
import Control.Arrow
import Data.List

getInts = map read . words <$> getLine :: IO [Int]

type PayPair = [Int]
type Price = Int
type Osatsu = Price
type Amount = Int

check :: Price -> Amount -> [Osatsu] -> PayPair
check _ _ [] = [-1]
check p a (o:[]) = if p /= a * o then [-1] else [a]
check p a (o:arr) = do
    if o * a < p then (-1):(map (\_ -> -1) arr)
    else do
        let pays = take (p `div` o + 1) [0..]
        let calcs = map tryPay pays
        let cands = filter (\x -> head x /= -1) calcs
        if length cands < 1 then head calcs else head cands
        where
            tryPay x = do
                let next = check (p - x * o) (a - x) arr
                if head next == -1 then (-1):next else x:next

main = do
    (a:p:_) <- getInts
    putStrLn $ map show >>> intercalate " " $ check p a [10000, 5000, 1000]

Submission Info

Submission Time
Task C - Otoshidama
User hanyutrans
Language Haskell (GHC 7.10.3)
Score 300
Code Size 894 Byte
Status AC
Exec Time 29 ms
Memory 1148 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 4
AC × 24
Set Name Test Cases
Sample a01, a02, a03, a04
All a01, a02, a03, a04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24
Case Name Status Exec Time Memory
a01 AC 2 ms 508 KB
a02 AC 2 ms 508 KB
a03 AC 3 ms 1020 KB
a04 AC 2 ms 1148 KB
b05 AC 2 ms 508 KB
b06 AC 2 ms 380 KB
b07 AC 1 ms 508 KB
b08 AC 3 ms 1020 KB
b09 AC 2 ms 1148 KB
b10 AC 3 ms 1020 KB
b11 AC 1 ms 508 KB
b12 AC 3 ms 1020 KB
b13 AC 3 ms 1020 KB
b14 AC 3 ms 1020 KB
b15 AC 2 ms 1148 KB
b16 AC 2 ms 1148 KB
b17 AC 2 ms 1148 KB
b18 AC 1 ms 508 KB
b19 AC 1 ms 636 KB
b20 AC 29 ms 1148 KB
b21 AC 3 ms 1020 KB
b22 AC 3 ms 1020 KB
b23 AC 2 ms 1148 KB
b24 AC 2 ms 1148 KB