結果

問題 No.1992 Tendon Walk
ユーザー sanao10000sanao10000
提出日時 2022-07-02 09:57:06
言語 Haskell
(9.8.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 4,942 bytes
コンパイル時間 7,009 ms
コンパイル使用メモリ 152,832 KB
最終ジャッジ日時 2024-11-27 02:34:51
合計ジャッジ時間 7,341 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )

Main.hs:13:1: error: [GHC-87110]
    Could not load module ‘Data.Set’.
    It is a member of the hidden package ‘containers-0.6.8’.
    Use -v to see a list of the files searched for.
   |
13 | import qualified Data.Set as S
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Main.hs:14:1: error: [GHC-87110]
    Could not load module ‘Data.Map’.
    It is a member of the hidden package ‘containers-0.6.8’.
    Use -v to see a list of the files searched for.
   |
14 | import qualified Data.Map as Map
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Main.hs:15:1: error: [GHC-87110]
    Could not load module ‘Data.Sequence’.
    It is a member of the hidden package ‘containers-0.6.8’.
    Use -v to see a list of the files searched for.
   |
15 | import qualified Data.Sequence as Seq
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Main.hs:23:1: error: [GHC-87110]
    Could not load module ‘Data.IntMap’.
    It is a member of the hidden package ‘containers-0.6.8’.
    Use -v to see a list of the files searched for.
   |
23 | import qualified Data.IntMap as IM
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Main.hs:25:1: error: [GHC-87110]
    Could not load module ‘Control.Monad.Trans.State’.
    It is a member of the hidden package ‘transformers-0.6.1.0’.
    Use -v to see a list of the files searched for.
   |
25 | import qualified Control.Monad.Trans.State as MTS
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ソースコード

diff #

{-# LANGUAGE BangPatterns , BlockArguments ,FlexibleContexts ,FlexibleInstances ,OverloadedStrings ,TypeApplications ,MultiParamTypeClasses ,TupleSections #-}
{-# OPTIONS_GHC -Wno-missing-methods #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}


import Control.Monad (replicateM,forM_,when,(<=<))
import Data.Maybe (fromJust)
import Data.Array.IO(IOUArray,IOArray)
import Data.Array.Unboxed(UArray,Ix)
import qualified Data.Array.MArray     as MA
import qualified Data.Array.IArray     as A
import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as S
import qualified Data.Map as Map
import qualified Data.Sequence as Seq
import Data.IORef


import Control.Monad.ST
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector.Generic as VG
import qualified Data.IntMap as IM
import Data.List(sort)
import qualified Control.Monad.Trans.State as MTS
import Control.Monad.State
import qualified Data.Foldable as F

-- ==================================================================
main :: IO ()
main = do
  x <- input @Int
  let calc = VU.fromList [2, 2, -1, -1, 2, -1, -1] 
  print $ solve calc 0 0 0 x

  pure()

solve :: VU.Vector Int -> Int -> Int -> Int -> Int -> Int
solve calc now ans index x 
  | now == x = ans
  | otherwise = solve calc (now + (calc VU.! index)) (ans + abs(calc VU.! index)) (rem(index + 1)7)x


-- ==================================================================


swapArray :: (MA.MArray a e m, Ix i) => a i e -> i -> i -> m ()
swapArray a i j = do
  ai <- MA.readArray a i
  aj <- MA.readArray a j
  MA.writeArray a i aj
  MA.writeArray a j ai

initUG :: Int -> [[Int]] -> A.Array Int [Int]
initUG n xs = A.accumArray (flip (:)) [] (0, n-1) $ concatMap (\[a, b] -> [(a, b), (b, a)]) xs

seqfront :: Seq.ViewL a -> a
seqfront(a Seq.:< b) = a
seqpop :: Seq.ViewL a -> Seq.Seq a
seqpop(a Seq.:< b) = b

modifyArray :: (MA.MArray a e m, Ix i) => a i e -> i -> (e -> e) -> m ()
modifyArray !a !i !f = MA.writeArray a i . f =<< MA.readArray a i
{-# INLINE modifyArray #-}

type Bs = BS.ByteString
type Height = Int
type Width = Int
type MutableArray2D any = IOUArray (Height,Width) any
type Array2D any = UArray (Height, Width) any

-- 初期化DP配列====================================================
class DPArray a where
    initDP :: Height -> Width -> a -> IO(MutableArray2D a)

instance DPArray Int where
  initDP = ((MA.newArray . ((0, 0) ,)) .) . (. subtract 1) . (,) . subtract 1
instance DPArray Double where
  initDP = ((MA.newArray . ((0, 0) ,)) .) . (. subtract 1) . (,) . subtract 1
instance DPArray Bool where
  initDP = ((MA.newArray . ((0, 0) ,)) .) . (. subtract 1) . (,) . subtract 1
-- =================================================================


-- 入力 =====================================================================================================================================================
class (Read a) => Input a where
  read' :: BS.ByteString -> a
  readArray2D :: Height -> Width -> BS.ByteString -> a

input :: Input a => IO a
input = read' <$> BS.getLine

inputs :: Input a => IO a
inputs = read' <$> BS.getContents

inputArray :: Input a => Int -> Int -> IO a
inputArray = flip flip BS.getContents . ((<$>) .) . readArray2D

instance Input Bs where
  read' = id

instance Input Int where
  read' = fst . fromJust . BS.readInt

instance Input Integer where
  read' = (read @Integer) . BS.unpack

instance Input Double where
  read' = read . BS.unpack

instance Input [Bs] where
  read' = BS.words

instance Input [Int] where
  read' = map (fst . fromJust . BS.readInt) . BS.words

instance Input [Double] where
  read' = map ((read @Double) . BS.unpack) . BS.words

instance Input [(Int, Bs)] where
  read' = map ((\[a, b] -> (fst (fromJust (BS.readInt a)), b)) . BS.words) . BS.lines

instance Input [(Bs, Int)] where
  read' = map ((\[a, b] -> (a, fst (fromJust (BS.readInt b)))) . BS.words) . BS.lines

instance Input [[Bs]] where
  read' = map BS.words . BS.lines

instance Input [[Int]] where
  read' = map (map (fst . fromJust . BS.readInt) . BS.words) . BS.lines

instance Input [[Double]] where
  read' = map (map ( (read @Double) . BS.unpack) . BS.words) . BS.lines

instance Input (Array2D Int) where
  readArray2D = flip flip ((map (fst . fromJust . BS.readInt) . BS.words) <=< BS.lines) . (((.) . A.listArray . ((0, 0) ,)) .) . (. subtract 1) . (,) . subtract 1

instance Input (Array2D Double) where
  readArray2D height width = A.listArray ((0, 0), (height - 1, width - 1)) . concatMap (map ((read @Double) . BS.unpack) . BS.words) . BS.lines

instance Input (Array2D Char) where
 readArray2D = flip flip (BS.unpack <=< BS.lines) . (((.) . A.listArray . ((0, 0) ,)) .) . (. subtract 1) . (,) . subtract 1
-- ============================================================================================================================================================
0