結果

問題 No.10 +か×か
ユーザー gigurururugigurururu
提出日時 2015-02-20 21:08:08
言語 Haskell
(9.8.2)
結果
AC  
実行時間 1,125 ms / 5,000 ms
コード長 729 bytes
コンパイル時間 2,870 ms
コンパイル使用メモリ 175,104 KB
実行使用メモリ 379,700 KB
最終ジャッジ日時 2024-05-08 11:43:33
合計ジャッジ時間 8,102 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1,125 ms
379,700 KB
testcase_04 AC 698 ms
277,004 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1,112 ms
379,568 KB
testcase_07 AC 737 ms
276,872 KB
testcase_08 AC 170 ms
77,572 KB
testcase_09 AC 439 ms
205,440 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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