結果
問題 | No.10 +か×か |
ユーザー | satonakatakumi |
提出日時 | 2021-08-15 12:28:36 |
言語 | Haskell (9.8.2) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,398 bytes |
コンパイル時間 | 1,678 ms |
コンパイル使用メモリ | 197,980 KB |
最終ジャッジ日時 | 2024-11-15 05:19:26 |
合計ジャッジ時間 | 2,368 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、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:25:13: error: [GHC-87543] Ambiguous occurrence ‘.>>.’. It could refer to either ‘Data.Bits..>>.’, imported from ‘Data.Bits’ at Main.hs:7:1-26, or ‘Main..>>.’, defined at Main.hs:47:1. | 25 | if (dpt .>>. (n - 2 - i)) `mod` 2 == 1 | ^^^^ Main.hs:32:38: error: [GHC-87543] Ambiguous occurrence ‘.<<.’. It could refer to either ‘Data.Bits..<<.’, imported from ‘Data.Bits’ at Main.hs:7:1-26, or ‘Main..<<.’, defined at Main.hs:51:1. | 32 | dp <- VUM.replicate (total + 1) (1 .<<. n) | ^^^^ Main.hs:35:41: error: [GHC-87543] Ambiguous occurrence ‘.<<.’. It could refer to either ‘Data.Bits..<<.’, imported from ‘Data.Bits’ at Main.hs:7:1-26, or ‘Main..<<.’, defined at Main.hs:51:1. | 35 | dp2 <- VUM.replicate (total + 1) (1 .<<. n) :: ST s (VUM.STVector s Int) | ^^^^ Main.hs:38:25: error: [GHC-87543] Ambiguous occurrence ‘.<<.’. It could refer to either ‘Data.Bits..<<.’, imported from ‘Data.Bits’ at Main.hs:7:1-26, or ‘Main..<<.’, defined at Main.hs:51:1. | 38 | unless (dpj == (1 .<<. n)) $ do | ^^^^
ソースコード
{-# LANGUAGE BangPatterns #-} import Control.Monad import Control.Monad.ST import Control.Monad.State import Control.Monad.Fix import Data.Bits import Data.Char import Data.Coerce import Data.Word 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 main :: IO () main = do n <- readLn :: IO Int total <- readLn :: IO Int as <- seqInput n let dp = solve n total as dpt = dp VU.! total rep (n - 1) $ \i -> do if (dpt .>>. (n - 2 - i)) `mod` 2 == 1 then putStr "*" else putStr "+" putStrLn "" solve :: Int -> Int -> VU.Vector Int -> VU.Vector Int solve n total as = VU.create $ do dp <- VUM.replicate (total + 1) (1 .<<. n) VUM.unsafeWrite dp (as VU.! 0) 0 rep1 n $ \i -> do dp2 <- VUM.replicate (total + 1) (1 .<<. n) :: ST s (VUM.STVector s Int) rep (total + 1) $ \j -> do dpj <- VUM.unsafeRead dp j unless (dpj == (1 .<<. n)) $ do when (j + as VU.! i <= total) $ VUM.unsafeModify dp2 (min (dpj * 2)) (j + as VU.! i) when (j * as VU.! i <= total) $ VUM.unsafeModify dp2 (min (dpj * 2 + 1)) (j * as VU.! i) VUM.unsafeMove dp dp2 return dp infixl 8 .>>., .<<. (.>>.) :: Bits b => b -> Int -> b (.>>.) = unsafeShiftR {-# INLINE (.>>.) #-} (.<<.) :: Bits b => b -> Int -> b (.<<.) = unsafeShiftL {-# INLINE (.<<.) #-} rep :: Monad m => Int -> (Int -> m ()) -> m () rep n = flip VFSM.mapM_ (stream 0 n) {-# INLINE rep #-} rep1 :: Monad m => Int -> (Int -> m ()) -> m () rep1 n = flip VFSM.mapM_ (stream 1 n) {-# INLINE rep1 #-} 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 #-} type Parser a = StateT BSC8.ByteString Maybe a runParser :: Parser a -> BSC8.ByteString -> Maybe (a, BSC8.ByteString) runParser = runStateT {-# INLINE runParser #-} int :: Parser Int int = coerce $ BSC8.readInt . BSC8.dropWhile isSpace {-# INLINE int #-} seqInput :: Int -> IO (VU.Vector Int) seqInput n = VU.unfoldrN n (runParser int) <$> BSC8.getLine {-# INLINE seqInput #-}