結果
| 問題 |
No.31 悪のミックスジュース
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2014-11-22 13:17:55 |
| 言語 | Haskell (9.10.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,034 bytes |
| コンパイル時間 | 13,519 ms |
| コンパイル使用メモリ | 231,872 KB |
| 実行使用メモリ | 11,264 KB |
| 最終ジャッジ日時 | 2025-01-02 20:06:57 |
| 合計ジャッジ時間 | 5,923 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 WA * 9 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.10.1/environments/default
[1 of 2] Compiling Main ( Main.hs, Main.o )
Main.hs:18:11: warning: [GHC-97441] [-Woverflowed-literals]
Literal 1001001001001001001001001 is out of the Int64 range -9223372036854775808..9223372036854775807
|
18 | inf = 1001001001001001001001001
| ^^^^^^^^^^^^^^^^^^^^^^^^^
[2 of 2] Linking a.out
ソースコード
import Control.Applicative
import Data.List (sortBy)
import Data.Int
import Data.Array
import qualified Data.Vector as V
import Debug.Trace
readInts :: IO [Int64]
readInts = map read . words <$> getLine
main = do
[n, v] <- readInts
cs <- readInts
let
comp (x,y) (x',y') = compare (x*y') (x'*y)
total = sum cs
cs' = V.fromList . sortBy comp $ zip (scanl1 (+) cs) [1..]
inf = 1001001001001001001001001
dp x
| x <= 0 = 0
| otherwise = table ! (n,x)
where
table = array ((0,0),(n,x)) [((i, j), f i j) | i <- [0..n], j <- [0..x]]
f _ 0 = 0
f 0 _ = inf
f i j = minimum [table!(i,j-1) + a, table!(i-1,j), if j-b >= 0 then table!(i,j-b) + a else inf]
where
(a, b) = cs' V.! (fromIntegral i-1)
f i = a * ((v-n) `div` b) + dp ((v-n) `mod` b)
where
(a, b) = cs' V.! i
in print $ if v < n
then total
else total + minimum (map f [0..fromIntegral n-1])
tottoripaper