結果

問題 No.357 品物の並び替え (Middle)
ユーザー こまる
提出日時 2020-11-05 15:52:45
言語 Haskell
(9.10.1)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,847 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 174,848 KB
最終ジャッジ日時 2024-11-14 23:54:05
合計ジャッジ時間 870 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:18:26: error: [GHC-87543]
    Ambiguous occurrence ‘.<<.’.
    It could refer to
       either ‘Data.Bits..<<.’,
              imported from ‘Data.Bits’ at Main.hs:4:1-26,
           or ‘Main..<<.’, defined at Main.hs:60:1.
   |
18 |   dp <- VUM.replicate (1 .<<. n) (0 :: Int)
   |                          ^^^^

Main.hs:19:10: error: [GHC-87543]
    Ambiguous occurrence ‘.<<.’.
    It could refer to
       either ‘Data.Bits..<<.’,
              imported from ‘Data.Bits’ at Main.hs:4:1-26,
           or ‘Main..<<.’, defined at Main.hs:60:1.
   |
19 |   rep (1 .<<. n) $ \bit -> rep n $ \v -> do
   |          ^^^^

Main.hs:20:22: error: [GHC-87543]
    Ambiguous occurrence ‘.<<.’.
    It could refer to
       either ‘Data.Bits..<<.’,
              imported from ‘Data.Bits’ at Main.hs:4:1-26,
           or ‘Main..<<.’, defined at Main.hs:60:1.
   |
20 |     when (bit .&. (1 .<<. v) == 0) $ do
   |                      ^^^^

Main.hs:23:26: error: [GHC-87543]
    Ambiguous occurrence ‘.<<.’.
    It could refer to
       either ‘Data.Bits..<<.’,
              imported from ‘Data.Bits’ at Main.hs:4:1-26,
           or ‘Main..<<.’, defined at Main.hs:60:1.
   |
23 |         when (bit .&. (1 .<<. i) /= 0) $ do
   |                          ^^^^

Main.hs:28:61: error: [GHC-87543]
    Ambiguous occurrence ‘.<<.’.
    It could refer to
       either ‘Data.Bits..<<.’,
              imported from ‘Data.Bits’ at Main.hs:4:1-26,
           or ‘Main..<<.’, defined at Main.hs:60:1.
   |
28 |       VUM.unsafeModify dp (max (item1 + item2)) (bit .|. (1 .<<. v))
   |                                                             ^^^^

Main.hs:29:35: error: [GHC-87543]
    Ambiguous occurrence ‘.<<.’.
    It could refer to
       either ‘Data.Bits..<<.’,

ソースコード

diff #
プレゼンテーションモードにする

{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Bits
import Data.Maybe
import Data.IORef
import qualified Data.ByteString.Char8 as BSC8
import qualified Data.Vector.Fusion.Stream.Monadic as VFSM
import qualified Data.Vector.Unboxed.Mutable as VUM
main :: IO ()
main = do
[n, m] <- map (read :: String -> Int) . words <$> getLine
score <- VUM.replicate (n * n) (0 :: Int)
rep m $ \_ -> do
[a, b, s] <- getIntList
VUM.unsafeWrite score (a * n + b) s
dp <- VUM.replicate (1 .<<. n) (0 :: Int)
rep (1 .<<. n) $ \bit -> rep n $ \v -> do
when (bit .&. (1 .<<. v) == 0) $ do
su <- newIORef (0 :: Int)
rep n $ \i -> do
when (bit .&. (1 .<<. i) /= 0) $ do
item <- VUM.unsafeRead score (i * n + v)
modifyIORef' su (+ item)
item1 <- VUM.unsafeRead dp bit
item2 <- readIORef su
VUM.unsafeModify dp (max (item1 + item2)) (bit .|. (1 .<<. v))
print =<< VUM.unsafeRead dp ((1 .<<. n) - 1)
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 #-}
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 #-}
infixl 8 .<<.
(.<<.) :: Bits b => b -> Int -> b
(.<<.) = unsafeShiftL
{-# INLINE (.<<.) #-}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0