結果

問題 No.10 +か×か
ユーザー gigurururu
提出日時 2015-02-20 21:08:08
言語 Haskell
(9.10.1)
結果
AC  
実行時間 1,171 ms / 5,000 ms
コード長 729 bytes
コンパイル時間 2,177 ms
コンパイル使用メモリ 175,104 KB
実行使用メモリ 379,688 KB
最終ジャッジ日時 2024-12-14 15:27:46
合計ジャッジ時間 7,145 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Control.Applicative
import Data.Maybe
import Data.Array

dfs :: Array (Int,Int) (Maybe String) ->Int -> Int -> Int -> [Int] -> Maybe String
dfs memo t n v []
  | v == t      = Just ""
  | otherwise   = Nothing
dfs memo t n v (x:xs)
  | v+x <= t && (isJust $ memo!(n+1,v+x)) =  Just ('+':(fromJust $ memo!(n+1,v+x)))
  | v*x <= t && (isJust $ memo!(n+1,v*x)) =  Just ('*':(fromJust $ memo!(n+1,v*x)))
  | otherwise                             =  Nothing

main :: IO()
main = do
  n     <- read <$> getLine
  total <- read <$> getLine
  (s:a) <- map read . words <$> getLine
  let memo = array ((1,s),(n,total)) [((i,j),dfs memo total i j $ drop i a) | i<-[1..n],j<-[s..total] ]
  putStrLn $ fromJust $ dfs memo total 0 s a
0