結果
問題 | No.59 鉄道の旅 |
ユーザー | aimy |
提出日時 | 2017-06-18 11:34:32 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 972 ms / 5,000 ms |
コード長 | 1,441 bytes |
コンパイル時間 | 10,223 ms |
コンパイル使用メモリ | 194,688 KB |
実行使用メモリ | 147,200 KB |
最終ジャッジ日時 | 2024-10-01 19:38:01 |
合計ジャッジ時間 | 20,666 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 722 ms
138,752 KB |
testcase_01 | AC | 720 ms
138,880 KB |
testcase_02 | AC | 722 ms
138,880 KB |
testcase_03 | AC | 721 ms
139,008 KB |
testcase_04 | AC | 972 ms
147,200 KB |
testcase_05 | AC | 726 ms
138,752 KB |
testcase_06 | AC | 728 ms
139,008 KB |
testcase_07 | AC | 738 ms
131,712 KB |
testcase_08 | AC | 755 ms
138,752 KB |
testcase_09 | AC | 755 ms
134,656 KB |
testcase_10 | AC | 718 ms
127,616 KB |
testcase_11 | AC | 703 ms
127,488 KB |
testcase_12 | AC | 723 ms
127,616 KB |
testcase_13 | AC | 712 ms
103,168 KB |
testcase_14 | AC | 723 ms
103,168 KB |
testcase_15 | AC | 638 ms
92,928 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
ソースコード
import Data.List import qualified Data.ByteString.Char8 as B import Data.Maybe data SegTree a = Leaf a | Node a (SegTree a) (SegTree a) deriving (Eq, Show) val :: SegTree a -> a val (Leaf v) = v val (Node v _ _) = v fromList :: (Num a) => Int -> [a] -> SegTree a fromList 1 [x] = Leaf x fromList n xs = Node (val left + val right) left right where n' = div n 2 (xs1,xs2) = splitAt n' xs left = fromList n' xs1 right = fromList (n-n') xs2 update :: (Num a) => Int -> SegTree a -> Int -> a -> SegTree a update 1 (Leaf v) 1 x = Leaf (v+x) update n (Node _ l r) i x | i <= n' = Node (val left + val r) left r | otherwise = Node (val l + val right) l right where n' = div n 2 left = update n' l i x right = update (n-n') r (i-n') x query :: (Num a) => Int -> SegTree a -> Int -> Int -> a query 1 (Leaf v) 1 1 = v query n (Node v l r) i j | (i,j) == (1,n) = v | j <= n' = query n' l i j | i > n' = query (n-n') r (i-n') (j-n') | otherwise = query n' l i n' + query (n-n') r 1 (j-n') where n' = div n 2 maxv = 1000000 main = do [_,k] <- map read . words <$> getLine ws <- map (fst . fromJust . B.readInt) . B.words <$> B.getContents let seg = fromList maxv (replicate maxv 0) print (freight k seg ws) freight k seg = val . foldl' (dp k) seg dp k seg w | w < 0 && query maxv seg (abs w) (abs w) /= 0 = update maxv seg (abs w) (-1) | w > 0 && query maxv seg w maxv < k = update maxv seg w 1 | otherwise = seg