結果
| 問題 |
No.286 Modulo Discount Store
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-11-04 21:04:49 |
| 言語 | Haskell (9.10.1) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,252 bytes |
| コンパイル時間 | 386 ms |
| コンパイル使用メモリ | 202,880 KB |
| 最終ジャッジ日時 | 2024-11-14 23:54:04 |
| 合計ジャッジ時間 | 944 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、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:16:9: error: [GHC-87543]
Ambiguous occurrence ‘.<<.’.
It could refer to
either ‘Data.Bits..<<.’,
imported from ‘Data.Bits’ at Main.hs:6:1-26,
or ‘Main..<<.’, defined at Main.hs:55:1.
|
16 | inf = 1 .<<. 30 - 1
| ^^^^
Main.hs:23:26: error: [GHC-87543]
Ambiguous occurrence ‘.<<.’.
It could refer to
either ‘Data.Bits..<<.’,
imported from ‘Data.Bits’ at Main.hs:6:1-26,
or ‘Main..<<.’, defined at Main.hs:55:1.
|
23 | ms <- VUM.unsafeNew (1 .<<. n) :: IO (VUM.IOVector Int)
| ^^^^
Main.hs:24:26: error: [GHC-87543]
Ambiguous occurrence ‘.<<.’.
It could refer to
either ‘Data.Bits..<<.’,
imported from ‘Data.Bits’ at Main.hs:6:1-26,
or ‘Main..<<.’, defined at Main.hs:55:1.
|
24 | dp <- VUM.replicate (1 .<<. n) inf
| ^^^^
Main.hs:25:10: error: [GHC-87543]
Ambiguous occurrence ‘.<<.’.
It could refer to
either ‘Data.Bits..<<.’,
imported from ‘Data.Bits’ at Main.hs:6:1-26,
or ‘Main..<<.’, defined at Main.hs:55:1.
|
25 | rep (1 .<<. n) $ \i -> do
| ^^^^
Main.hs:26:34: error: [GHC-87543]
Ambiguous occurrence ‘.<<.’.
It could refer to
either ‘Data.Bits..<<.’,
imported from ‘Data.Bits’ at Main.hs:6:1-26,
or ‘Main..<<.’, defined at Main.hs:55:1.
|
26 | rep n $ \j -> when (i .&. (1 .<<. j) /= 0) $ VUM.unsafeModify ms (+ xs VU.! j) i
| ^^^^
Main.hs:29:10: error: [GHC-87543]
Ambiguous occurrence ‘.<<.’.
It could refer to
either ‘Data.Bits..<<.’,
imported from ‘Data.Bits’ at Main.h
ソースコード
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MagicHash #-}
import Control.Monad
import Control.Monad.State
import Data.Bits
import Data.Coerce
import Data.Char
import GHC.Exts
import qualified Data.ByteString.Char8 as BSC8
import qualified Data.Vector.Fusion.Stream.Monadic as VFSM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
inf :: Int
inf = 1 .<<. 30 - 1
{-# INLINE inf #-}
main :: IO ()
main = do
n <- readLn :: IO Int
xs <- parseN1 n
ms <- VUM.unsafeNew (1 .<<. n) :: IO (VUM.IOVector Int)
dp <- VUM.replicate (1 .<<. n) inf
rep (1 .<<. n) $ \i -> do
rep n $ \j -> when (i .&. (1 .<<. j) /= 0) $ VUM.unsafeModify ms (+ xs VU.! j) i
VUM.unsafeModify ms (`mod` 1000) i
VUM.unsafeWrite dp 0 0
rep (1 .<<. n) $ \i -> rep n $ \j -> do
let next = i .|. (1 .<<. j)
item <- VUM.unsafeRead ms i
let value = max 0 (xs VU.! j - item)
dpi <- VUM.unsafeRead dp i
VUM.unsafeModify dp (min (dpi + value)) next
print =<< VUM.unsafeRead dp (1 .<<. n - 1)
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 #-}
parseN1 :: Int -> IO (VU.Vector Int)
parseN1 n = VU.unfoldrN n (runCParser int) <$> BSC8.getContents
{-# INLINE parseN1 #-}
infixl 8 .<<., .>>., .>>>.
infixl 6 .^.
(.<<.) :: Bits b => b -> Int -> b
(.<<.) = unsafeShiftL
{-# INLINE (.<<.) #-}
(.>>.) :: Bits b => b -> Int -> b
(.>>.) = unsafeShiftR
{-# INLINE (.>>.) #-}
(.>>>.) :: Int -> Int -> Int
(.>>>.) (I# x#) (I# i#) = I# (uncheckedIShiftRL# x# i#)
{-# INLINE (.>>>.) #-}
(.^.) :: Bits b => b -> b -> b
(.^.) = xor
{-# INLINE (.^.) #-}
stream :: Monad m => Int -> Int -> VFSM.Stream m Int
stream !l !r = VFSM.Stream step l
where
step x
| x < r = return $ VFSM.Yield x (x + 1)
| otherwise = return $ VFSM.Done
{-# INLINE [0] step #-}
{-# INLINE [1] stream #-}
rep :: Monad m => Int -> (Int -> m ()) -> m ()
rep n = flip VFSM.mapM_ (stream 0 n)
{-# INLINE rep #-}