Submission #70805806
Source Code Expand
{-# OPTIONS_GHC -Wall #-}
{-# OPTIONS_GHC -Wname-shadowing #-} -- 内側のスコープの値と同じ名前が外側のスコープにあるとき警告する
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List
import Data.Array.Unboxed qualified as A
import Data.ByteString.Char8 qualified as BS
import Control.Monad.ST -- runST / ST s で使用
import Data.Array.ST -- STUArray で使用
import qualified Data.Array.MArray as AM
readInts :: IO [Int]
readInts = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
{-
- #DP 方針は時間内に立てられたが残り1分なので諦めた
-}
main :: IO ()
main = do
n <- readLn :: IO Int
whbs <- replicateM n $ do
[w,h,b] <- readInts
return (w,h,b)
let wSum = sum $ map (\(w,h,b) -> w) whbs
let wSum_2 = wSum `div` 2
print $ maximum $ solve n wSum_2 whbs
solve :: Int -> Int -> [(Int,Int,Int)] -> [Int] -- A.UArray (Int,Int) Int
solve n wSum_2 whbs = runST $ do
arr <- AM.newArray ((0,0),(n,wSum_2)) (minBound::Int) :: ST s (STUArray s (Int,Int) Int) -- 型に注意
AM.writeArray arr (0,0) 0 -- DPテーブルの初期値設定
forM_ [0..n-1] $ \i -> do
let (w,h,b) = whbs !! i
forM_ [0..wSum_2] $ \j -> do
val0 <- AM.readArray arr (i,j)
when (val0 /= (minBound::Int)) $ do
when ( j+w <= wSum_2 ) $ do
val1 <- AM.readArray arr (i+1,j+w)
AM.writeArray arr (i+1,j+w) $ max val1 (val0 + h)
when ( j <= wSum_2 ) $ do
val1 <- AM.readArray arr (i+1,j)
AM.writeArray arr (i+1,j) $ max val1 (val0 + b)
forM [0..wSum_2] $ \j -> do
val <- AM.readArray arr (n,j)
return val
Submission Info
| Submission Time | |
|---|---|
| Task | D - Robot Customize |
| User | haskboy |
| Language | Haskell (GHC 9.8.4) |
| Score | 400 |
| Code Size | 1742 Byte |
| Status | AC |
| Exec Time | 403 ms |
| Memory | 511868 KiB |
Compile Error
Configuration is affected by the following files:
- cabal.project
- cabal.project.freeze
- cabal.project.local
app/Main.hs:9:1: warning: [GHC-66111] [-Wunused-imports]
The qualified import of ‘Data.Array.Unboxed’ is redundant
except perhaps to import instances from ‘Data.Array.Unboxed’
To import instances alone, use: import Data.Array.Unboxed()
|
9 | import Data.Array.Unboxed qualified as A
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/Main.hs:10:1: warning: [GHC-66111] [-Wunused-imports]
The qualified import of ‘Data.ByteString.Char8’ is redundant
except perhaps to import instances from ‘Data.ByteString.Char8’
To import instances alone, use: import Data.ByteString.Char8()
|
10 | import Data.ByteString.Char8 qualified as BS
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/Main.hs:29:29: warning: [GHC-40910] [-Wunused-matches]
Defined but not used: ‘h’
|
29 | let wSum = sum $ map (\(w,h,b) -> w) whbs
| ^
app/Main.hs:29:31: warning: [GHC-40910] [-Wunused-matches]
Defined but not used: ‘b’
|
29 | let wSum = sum $ map (\(w,h,b) -> w) whbs
| ^
Configuration is affected by the following files:
- cabal.project
- cabal.project.freeze
- cabal.project.local
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 16 ms | 8396 KiB |
| 00_sample_01.txt | AC | 2 ms | 8396 KiB |
| 00_sample_02.txt | AC | 2 ms | 8376 KiB |
| 00_sample_03.txt | AC | 3 ms | 9288 KiB |
| 01_random_03.txt | AC | 251 ms | 256720 KiB |
| 01_random_04.txt | AC | 246 ms | 256660 KiB |
| 01_random_05.txt | AC | 254 ms | 262880 KiB |
| 01_random_06.txt | AC | 251 ms | 262100 KiB |
| 01_random_07.txt | AC | 255 ms | 266452 KiB |
| 01_random_08.txt | AC | 255 ms | 263856 KiB |
| 01_random_09.txt | AC | 248 ms | 259224 KiB |
| 01_random_10.txt | AC | 254 ms | 263812 KiB |
| 01_random_11.txt | AC | 254 ms | 263536 KiB |
| 01_random_12.txt | AC | 169 ms | 166804 KiB |
| 01_random_13.txt | AC | 58 ms | 63636 KiB |
| 01_random_14.txt | AC | 46 ms | 53484 KiB |
| 01_random_15.txt | AC | 94 ms | 97644 KiB |
| 01_random_16.txt | AC | 33 ms | 39052 KiB |
| 01_random_17.txt | AC | 251 ms | 257708 KiB |
| 01_random_18.txt | AC | 258 ms | 268056 KiB |
| 01_random_19.txt | AC | 253 ms | 262332 KiB |
| 01_random_20.txt | AC | 243 ms | 253744 KiB |
| 01_random_21.txt | AC | 248 ms | 258360 KiB |
| 01_random_22.txt | AC | 51 ms | 57224 KiB |
| 01_random_23.txt | AC | 3 ms | 9180 KiB |
| 01_random_24.txt | AC | 2 ms | 8752 KiB |
| 01_random_25.txt | AC | 252 ms | 260968 KiB |
| 01_random_26.txt | AC | 263 ms | 270452 KiB |
| 01_random_27.txt | AC | 249 ms | 258136 KiB |
| 01_random_28.txt | AC | 257 ms | 265556 KiB |
| 01_random_29.txt | AC | 258 ms | 267580 KiB |
| 01_random_30.txt | AC | 262 ms | 269672 KiB |
| 01_random_31.txt | AC | 181 ms | 194980 KiB |
| 01_random_32.txt | AC | 95 ms | 97372 KiB |
| 01_random_33.txt | AC | 2 ms | 8484 KiB |
| 01_random_34.txt | AC | 2 ms | 8680 KiB |
| 01_random_35.txt | AC | 251 ms | 258904 KiB |
| 01_random_36.txt | AC | 244 ms | 255768 KiB |
| 01_random_37.txt | AC | 259 ms | 267772 KiB |
| 01_random_38.txt | AC | 245 ms | 254000 KiB |
| 01_random_39.txt | AC | 258 ms | 266008 KiB |
| 01_random_40.txt | AC | 248 ms | 259116 KiB |
| 01_random_41.txt | AC | 253 ms | 262528 KiB |
| 01_random_42.txt | AC | 252 ms | 260032 KiB |
| 01_random_43.txt | AC | 101 ms | 104268 KiB |
| 01_random_44.txt | AC | 211 ms | 223912 KiB |
| 01_random_45.txt | AC | 181 ms | 179080 KiB |
| 01_random_46.txt | AC | 13 ms | 18048 KiB |
| 01_random_47.txt | AC | 71 ms | 74432 KiB |
| 01_random_48.txt | AC | 372 ms | 511828 KiB |
| 01_random_49.txt | AC | 403 ms | 511680 KiB |
| 01_random_50.txt | AC | 368 ms | 511868 KiB |
| 01_random_51.txt | AC | 8 ms | 15924 KiB |
| 01_random_52.txt | AC | 82 ms | 94784 KiB |