結果

問題 No.10 +か×か
コンテスト
ユーザー gigurururu
提出日時 2015-02-20 21:08:08
言語 Haskell
(9.12.2)
結果
AC  
実行時間 1,226 ms / 5,000 ms
コード長 729 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,813 ms
コンパイル使用メモリ 183,936 KB
実行使用メモリ 381,708 KB
最終ジャッジ日時 2025-12-06 14:30:27
合計ジャッジ時間 10,064 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.10.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #
raw source code

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