結果
問題 | No.1 道のショートカット |
ユーザー | こまる |
提出日時 | 2020-11-21 03:33:36 |
言語 | Haskell (9.8.2) |
結果 |
AC
|
実行時間 | 70 ms / 5,000 ms |
コード長 | 11,944 bytes |
コンパイル時間 | 9,727 ms |
コンパイル使用メモリ | 254,464 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-23 14:22:47 |
合計ジャッジ時間 | 12,215 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,376 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 32 ms
5,376 KB |
testcase_09 | AC | 26 ms
5,376 KB |
testcase_10 | AC | 50 ms
5,376 KB |
testcase_11 | AC | 63 ms
5,376 KB |
testcase_12 | AC | 44 ms
5,376 KB |
testcase_13 | AC | 43 ms
5,376 KB |
testcase_14 | AC | 4 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 12 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 7 ms
5,376 KB |
testcase_19 | AC | 6 ms
5,376 KB |
testcase_20 | AC | 15 ms
5,376 KB |
testcase_21 | AC | 9 ms
5,376 KB |
testcase_22 | AC | 7 ms
5,376 KB |
testcase_23 | AC | 67 ms
5,376 KB |
testcase_24 | AC | 55 ms
5,376 KB |
testcase_25 | AC | 16 ms
5,376 KB |
testcase_26 | AC | 11 ms
5,376 KB |
testcase_27 | AC | 57 ms
5,376 KB |
testcase_28 | AC | 2 ms
5,376 KB |
testcase_29 | AC | 70 ms
5,376 KB |
testcase_30 | AC | 19 ms
5,376 KB |
testcase_31 | AC | 36 ms
5,376 KB |
testcase_32 | AC | 24 ms
5,376 KB |
testcase_33 | AC | 20 ms
5,376 KB |
testcase_34 | AC | 42 ms
5,376 KB |
testcase_35 | AC | 47 ms
5,376 KB |
testcase_36 | AC | 46 ms
5,376 KB |
testcase_37 | AC | 42 ms
5,376 KB |
testcase_38 | AC | 6 ms
5,376 KB |
testcase_39 | AC | 6 ms
5,376 KB |
testcase_40 | AC | 22 ms
5,376 KB |
testcase_41 | AC | 9 ms
5,376 KB |
testcase_42 | AC | 2 ms
5,376 KB |
testcase_43 | AC | 2 ms
5,376 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
ソースコード
{-# LANGUAGE BangPatterns #-} {-# LANGUAGE BinaryLiterals #-} {-# LANGUAGE CPP #-} {-# LANGUAGE DefaultSignatures #-} {-# LANGUAGE DerivingVia #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE NumericUnderscores #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} import Control.Monad.Cont import Control.Monad.ST import Control.Monad.State import Data.Bool import Data.Char import Data.Coerce import Data.IORef import Data.Int import Data.Maybe import Data.Word import System.IO import qualified Data.ByteString as BS import qualified Data.ByteString.Builder as BSB import qualified Data.ByteString.Char8 as BSC8 import qualified Data.Vector.Fusion.Stream.Monadic as VFSM import qualified Data.Vector.Generic as VG import qualified Data.Vector.Unboxed as VU import qualified Data.Vector.Unboxed.Mutable as VUM inf :: Int inf = 10_000_000_000 {-# INLINE inf #-} main :: IO () main = do n <- readLn :: IO Int c <- readLn :: IO Int v <- readLn :: IO Int s <- seqInput v t <- seqInput v y <- seqInput v m <- seqInput v dp <- VUM.replicate (60 * 301) inf VUM.unsafeWrite dp 301 0 range 0 50 $ \_ -> rep v $ \j -> range (y VU.! j) 300 $ \k -> do item <- VUM.unsafeRead dp ((s VU.! j) * 301 + (k - y VU.! j)) VUM.unsafeModify dp (min (item + m VU.! j)) ((t VU.! j) * 301 + k) mn <- newIORef inf rep1' c $ \i -> do item <- VUM.unsafeRead dp (n * 301 + i) modifyIORef' mn (min item) mn' <- readIORef mn print $ bool mn' (-1) (mn' == inf) rep :: Monad m => Int -> (Int -> m ()) -> m () rep n = flip VFSM.mapM_ (streamG 0 (n - 1) const 0 (+) 1) {-# INLINE rep #-} rep' :: Monad m => Int -> (Int -> m ()) -> m () rep' n = flip VFSM.mapM_ (streamG 0 n const 0 (+) 1) {-# INLINE rep' #-} rep1 :: Monad m => Int -> (Int -> m ()) -> m () rep1 n = flip VFSM.mapM_ (streamG 1 (n - 1) const 0 (+) 1) {-# INLINE rep1 #-} rep1' :: Monad m => Int -> (Int -> m ()) -> m () rep1' n = flip VFSM.mapM_ (streamG 1 n const 0 (+) 1) {-# INLINE rep1' #-} rev :: Monad m => Int -> (Int -> m ()) -> m () rev n = flip VFSM.mapM_ (streamRG (n - 1) 0 const 0 (-) 1) {-# INLINE rev #-} rev' :: Monad m => Int -> (Int -> m ()) -> m () rev' n = flip VFSM.mapM_ (streamRG n 0 const 0 (-) 1) {-# INLINE rev' #-} rev1 :: Monad m => Int -> (Int -> m ()) -> m () rev1 n = flip VFSM.mapM_ (streamRG (n - 1) 1 const 0 (-) 1) {-# INLINE rev1 #-} rev1' :: Monad m => Int -> (Int -> m ()) -> m () rev1' n = flip VFSM.mapM_ (streamRG n 1 const 0 (-) 1) {-# INLINE rev1' #-} range :: Monad m => Int -> Int -> (Int -> m ()) -> m () range l r = flip VFSM.mapM_ (streamG l r const 0 (+) 1) {-# INLINE range #-} rangeR :: Monad m => Int -> Int -> (Int -> m ()) -> m () rangeR r l = flip VFSM.mapM_ (streamRG r l const 0 (-) 1) {-# INLINE rangeR #-} forP :: Monad m => Int -> (Int -> m ()) -> m () forP p = flip VFSM.mapM_ (streamG 2 p (^) 2 (+) 1) {-# INLINE forP #-} forG :: Monad m => Int -> Int -> (Int -> Int -> Int) -> Int -> (Int -> Int -> Int) -> Int -> (Int -> m ()) -> m () forG l r f p g d = flip VFSM.mapM_ (streamG l r f p g d) {-# INLINE forG #-} forRG :: Monad m => Int -> Int -> (Int -> Int -> Int) -> Int -> (Int -> Int -> Int) -> Int -> (Int -> m ()) -> m () forRG r l f p g d = flip VFSM.mapM_ (streamRG r l f p g d) {-# INLINE forRG #-} streamG :: Monad m => Int -> Int -> (Int -> Int -> Int) -> Int -> (Int -> Int -> Int) -> Int -> VFSM.Stream m Int streamG !l !r !f !p !g !d = VFSM.Stream step l where step x | f x p <= r = return $ VFSM.Yield x (g x d) | otherwise = return VFSM.Done {-# INLINE [0] step #-} {-# INLINE [1] streamG #-} streamRG :: Monad m => Int -> Int -> (Int -> Int -> Int) -> Int -> (Int -> Int -> Int) -> Int -> VFSM.Stream m Int streamRG !r !l !f !p !g !d = VFSM.Stream step r where step x | f x p >= l = return $ VFSM.Yield x (g x d) | otherwise = return VFSM.Done {-# INLINE [0] step #-} {-# INLINE [1] streamRG #-} withBreakIO :: ((r -> ContT r IO b) -> ContT r IO r) -> IO r withBreakIO = flip runContT pure . callCC {-# INLINE withBreakIO #-} withBreakST :: ((r -> ContT r (ST s) b) -> ContT r (ST s) r) -> (ST s) r withBreakST = flip runContT pure . callCC {-# INLINE withBreakST #-} type CParser a = StateT BSC8.ByteString Maybe a runCParser :: CParser a -> BSC8.ByteString -> Maybe (a, BSC8.ByteString) runCParser = runStateT {-# INLINE runCParser #-} int :: CParser Int int = coerce $ BSC8.readInt . BSC8.dropWhile isSpace {-# INLINE int #-} int1 :: CParser Int int1 = fmap (subtract 1) int {-# INLINE int1 #-} char :: CParser Char char = coerce BSC8.uncons {-# INLINE char #-} byte :: CParser Word8 byte = coerce BS.uncons {-# INLINE byte #-} skipSpaces :: CParser () skipSpaces = modify' (BSC8.dropWhile isSpace) {-# INLINE skipSpaces #-} seqInput :: Int -> IO (VU.Vector Int) seqInput n = VU.unfoldrN n (runCParser int) <$> BSC8.getLine {-# INLINE seqInput #-} parseN1 :: Int -> IO (VU.Vector Int) parseN1 n = VU.unfoldrN n (runCParser int) <$> BSC8.getContents {-# INLINE parseN1 #-} parseN2 :: Int -> IO (VU.Vector (Int, Int)) parseN2 n = VU.unfoldrN n (runCParser $ (,) <$> int <*> int) <$> BSC8.getContents {-# INLINE parseN2 #-} parseN3 :: Int -> IO (VU.Vector (Int, Int, Int)) parseN3 n = VU.unfoldrN n (runCParser $ (,,) <$> int <*> int <*> int) <$> BSC8.getContents {-# INLINE parseN3 #-} parseN4 :: Int -> IO (VU.Vector (Int, Int, Int, Int)) parseN4 n = VU.unfoldrN n (runCParser $ (,,,) <$> int <*> int <*> int <*> int) <$> BSC8.getContents {-# INLINE parseN4 #-} parseN5 :: Int -> IO (VU.Vector (Int, Int, Int, Int, Int)) parseN5 n = VU.unfoldrN n (runCParser $ (,,,,) <$> int <*> int <*> int <*> int <*> int) <$> BSC8.getContents {-# INLINE parseN5 #-} parseANBN :: Int -> IO (VU.Vector Int, VU.Vector Int) parseANBN n = VU.unzip . VU.unfoldrN n (runCParser $ (,) <$> int <*> int) <$> BSC8.getContents {-# INLINE parseANBN #-} parseANBNCN :: Int -> IO (VU.Vector Int, VU.Vector Int, VU.Vector Int) parseANBNCN n = VU.unzip3 . VU.unfoldrN n (runCParser $ (,,) <$> int <*> int <*> int) <$> BSC8.getContents {-# INLINE parseANBNCN #-} type Query3 = (Int, Int, Int) query3Parser :: CParser Query3 query3Parser = do skipSpaces t <- char case t of '0' -> (,,) 0 <$> int <*> int _ -> (,,) 1 <$> int <*> pure 0 parseQ3 :: Int -> IO (VU.Vector Query3) parseQ3 n = VU.unfoldrN n (runCParser query3Parser) <$> BSC8.getContents {-# INLINE parseQ3 #-} type Query5 = (Int, Int, Int, Int, Int) query5Parser :: CParser Query5 query5Parser = do skipSpaces t <- char case t of '0' -> (,,,,) 0 <$> int <*> int <*> int <*> int _ -> (,,,,) 1 <$> int <*> int <*> pure 0 <*> pure 0 parseQ5 :: Int -> IO (VU.Vector Query5) parseQ5 n = VU.unfoldrN n (runCParser query5Parser) <$> BSC8.getContents {-# INLINE parseQ5 #-} readInt :: BSC8.ByteString -> Int readInt = fst . fromJust . BSC8.readInt {-# INLINE readInt #-} getInt :: IO Int getInt = readInt <$> BSC8.getLine {-# INLINE getInt #-} readIntList :: BSC8.ByteString -> [Int] readIntList = map readInt . BSC8.words {-# INLINE readIntList #-} getIntList :: IO [Int] getIntList = readIntList <$> BSC8.getLine {-# INLINE getIntList #-} readInteger :: BSC8.ByteString -> Integer readInteger = fst . fromJust . BSC8.readInteger {-# INLINE readInteger #-} getInteger :: IO Integer getInteger = readInteger <$> BSC8.getLine {-# INLINE getInteger #-} readIntegerList :: BSC8.ByteString -> [Integer] readIntegerList = map readInteger . BSC8.words {-# INLINE readIntegerList #-} getIntegerList :: IO [Integer] getIntegerList = readIntegerList <$> BSC8.getLine {-# INLINE getIntegerList #-} class ShowAsBuilder a where showAsBuilder :: a -> BSB.Builder default showAsBuilder :: (Show a) => a -> BSB.Builder showAsBuilder = BSB.string8 . show instance ShowAsBuilder Int where showAsBuilder = BSB.intDec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Int8 where showAsBuilder = BSB.int8Dec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Int16 where showAsBuilder = BSB.int16Dec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Int32 where showAsBuilder = BSB.int32Dec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Int64 where showAsBuilder = BSB.int64Dec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Word8 where showAsBuilder = BSB.word8Dec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Word16 where showAsBuilder = BSB.word16Dec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Word32 where showAsBuilder = BSB.word32Dec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Word64 where showAsBuilder = BSB.word64Dec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Integer where showAsBuilder = BSB.integerDec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Float where showAsBuilder = BSB.floatDec {-# INLINE showAsBuilder #-} instance ShowAsBuilder Double where showAsBuilder = BSB.doubleDec {-# INLINE showAsBuilder #-} instance (ShowAsBuilder a, VG.Vector v a) => ShowAsBuilder (v a) where showAsBuilder = v2BSpcSep putBuilder :: BSB.Builder -> IO () putBuilder = BSB.hPutBuilder stdout {-# INLINE putBuilder #-} printVecInLines :: (VG.Vector v a, ShowAsBuilder a) => v a -> IO () printVecInLines = putBuilder . v2BLines {-# INLINE printVecInLines #-} printVecInSpcSepLn :: (VG.Vector v a, ShowAsBuilder a) => v a -> IO () printVecInSpcSepLn = putBuilder . v2BSpcSepLn {-# INLINE printVecInSpcSepLn #-} v2BSpcSepLn :: (VG.Vector v a, ShowAsBuilder a) => v a -> BSB.Builder v2BSpcSepLn = v2BSpcSepLnWith showAsBuilder {-# INLINE v2BSpcSepLn #-} v2BSpcSep :: (VG.Vector v a, ShowAsBuilder a) => v a -> BSB.Builder v2BSpcSep = v2BSpcSepWith showAsBuilder {-# INLINE v2BSpcSep #-} v2BConcat:: (VG.Vector v a, ShowAsBuilder a) => v a -> BSB.Builder v2BConcat = v2BConcatWith showAsBuilder {-# INLINE v2BConcat #-} v2BLines:: (VG.Vector v a, ShowAsBuilder a) => v a -> BSB.Builder v2BLines = v2BLinesWith showAsBuilder {-# INLINE v2BLines #-} v2BSpcSepLnWith :: VG.Vector v a => (a -> BSB.Builder) -> v a -> BSB.Builder v2BSpcSepLnWith = v2BSpcSepPostfWith "\n" {-# INLINE v2BSpcSepLnWith #-} v2BSpcSepWith :: VG.Vector v a => (a -> BSB.Builder) -> v a -> BSB.Builder v2BSpcSepWith = v2BSpcSepPostfWith "" {-# INLINE v2BSpcSepWith #-} v2BConcatWith :: VG.Vector v a => (a -> BSB.Builder) -> v a -> BSB.Builder v2BConcatWith showFct = VG.foldr ((<>) . showFct) mempty {-# INLINE v2BConcatWith #-} v2BLinesWith :: VG.Vector v a => (a -> BSB.Builder) -> v a -> BSB.Builder v2BLinesWith showFct = VG.foldr (\a -> (showFct a <>) . (BSB.char7 '\n' <>)) mempty {-# INLINE v2BLinesWith #-} v2BSpcSepPostf :: (VG.Vector v a, ShowAsBuilder a) => BS.ByteString -> v a -> BSB.Builder v2BSpcSepPostf = (`v2BSpcSepPostfWith` showAsBuilder) {-# INLINE v2BSpcSepPostf #-} v2BSpcSepPostfWith :: VG.Vector v a => BS.ByteString -> (a -> BSB.Builder) -> v a -> BSB.Builder v2BSpcSepPostfWith = vecToBuilder "" " " {-# INLINE v2BSpcSepPostfWith #-} vecToBuilder :: VG.Vector v a => BS.ByteString -> BS.ByteString -> BS.ByteString -> (a -> BSB.Builder) -> v a -> BSB.Builder vecToBuilder !prefix !separator !postfix = vecToBuilder_ (BSB.byteString prefix) (BSB.byteString separator) (BSB.byteString postfix) {-# INLINE vecToBuilder #-} vecToBuilder_ :: VG.Vector v a => BSB.Builder -> BSB.Builder -> BSB.Builder -> (a -> BSB.Builder) -> v a -> BSB.Builder vecToBuilder_ !prefix !separator !postfix showFct vec = prefix <> VG.foldr (\a rest !prefx -> prefx <> (showFct a <> rest separator)) (const postfix) vec mempty {-# INLINE vecToBuilder_ #-}