結果

問題 No.10 +か×か
ユーザー gigurururugigurururu
提出日時 2015-02-20 21:08:08
言語 Haskell
(9.8.2)
結果
AC  
実行時間 1,081 ms / 5,000 ms
コード長 729 bytes
コンパイル時間 5,708 ms
コンパイル使用メモリ 160,288 KB
実行使用メモリ 383,012 KB
最終ジャッジ日時 2023-08-21 06:10:46
合計ジャッジ時間 10,568 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,884 KB
testcase_01 AC 2 ms
6,960 KB
testcase_02 AC 2 ms
6,896 KB
testcase_03 AC 1,063 ms
382,980 KB
testcase_04 AC 672 ms
278,576 KB
testcase_05 AC 3 ms
7,048 KB
testcase_06 AC 1,081 ms
383,012 KB
testcase_07 AC 712 ms
278,640 KB
testcase_08 AC 174 ms
79,052 KB
testcase_09 AC 433 ms
207,388 KB
testcase_10 AC 4 ms
8,328 KB
testcase_11 AC 3 ms
7,184 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 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