結果
問題 | No.1268 Fruit Rush 2 |
ユーザー |
![]() |
提出日時 | 2021-08-31 17:37:54 |
言語 | Haskell (9.10.1) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 9,360 bytes |
コンパイル時間 | 644 ms |
コンパイル使用メモリ | 155,904 KB |
最終ジャッジ日時 | 2024-11-15 01:45:36 |
合計ジャッジ時間 | 2,265 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、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:21:75: error: [GHC-61689] Module ‘Control.Monad.State’ does not export ‘when’. | 21 | import Control.Monad.State (StateT (..), modify', when) | ^^^^
ソースコード
LANGUAGELANGUAGELANGUAGE-- module Yukicoder.No1268 whereimportControl.MonadwhenimportData.BitsBits,(.|.)importData.CharisSpaceimportData.CoercecoerceimportqualifiedData.FoldableasFimportData.IORefmodifyIORef',newIORef,readIORefimportData.MaybefromJustimportData.WordWord,Word,WordimportUnsafe.CoerceunsafeCoerceimportqualifiedData.ByteStringasBSimportqualifiedData.ByteString.CharasBSCimportControl.Monad.StateStateT(..),modify',whenimportqualifiedData.Vector.Fusion.Stream.MonadicasVFSMimportqualifiedData.Vector.UnboxedasVUimportqualifiedData.Vector.Unboxed.MutableasVUMmain::IO()main = don <- readLn :: IO Intas <- seqInput nlet ax = radixSortNonNegative asdp <- VUM.replicate (n + 1) 0 :: IO (VUM.IOVector Int)rev' n $ \i -> dowhen (i + 1 < n && (2 + ax VU.! i) == ax VU.! (i + 1)) $ dodpi1 <- VUM.unsafeRead dp (i + 1)VUM.unsafeWrite dp i (dpi1 + 1)when (i + 2 < n && (2 + ax VU.! i) == ax VU.! (i + 2)) $ dodpi2 <- VUM.unsafeRead dp (i + 2)VUM.unsafeWrite dp i (dpi2 + 1)ans <- newIORef nrep (n - 1) $ \i -> dowhen (ax VU.! i + 1 == ax VU.! (i + 1)) $ dodpi1 <- VUM.unsafeRead dp (i + 1)modifyIORef' ans (+ (dpi1 + 1))readIORef ans >>= printstream::Monadm=>Int->Int->VFSMStreammIntstream !l !r = VFSM.Stream step lwherestep x| x < r = return $ VFSM.Yield x (x + 1)| otherwise = return VFSM.DoneINLINEINLINErep, rep', rep1, rep1' :: Monad m => Int -> (Int -> m ()) -> m ()rep n = flip VFSM.mapM_ (stream 0 n)INLINErep' n = flip VFSM.mapM_ (stream 0 (n + 1))INLINErep1 n = flip VFSM.mapM_ (stream 1 n)INLINErep1' n = flip VFSM.mapM_ (stream 1 (n + 1))INLINEstreamR::Monadm=>Int->Int->VFSMStreammIntstreamR !l !r = VFSM.Stream step (r - 1)wherestep x| x >= l = return $ VFSM.Yield x (x - 1)| otherwise = return VFSM.DoneINLINEINLINErev, rev', rev1, rev1' :: Monad m => Int -> (Int -> m ()) -> m ()rev !n = flip VFSM.mapM_ (streamR 0 n)INLINErev' !n = flip VFSM.mapM_ (streamR 0 (n + 1))INLINErev1 !n = flip VFSM.mapM_ (streamR 1 n)INLINErev1' !n = flip VFSM.mapM_ (streamR 1 (n + 1))INLINEinfixl 8 .<<., .>>.(.<<.)::Bitsb=>b->Int->b(.<<.) = unsafeShiftLINLINE(.>>.)::Bitsb=>b->Int->b(.>>.) = unsafeShiftRINLINEclassWordEncodeawhereencode64::a->Word64decode64::Word64->aencodeNonNegative64::a->Word64encodeNonNegative64 = encode64decodeNonNegative64::Word64->adecodeNonNegative64 = decode64instanceWord64EncodeIntwhereencode64 x = unsafeCoerce $ x + 0x3fffffffffffffffdecode64 x = unsafeCoerce x - 0x3fffffffffffffffencodeNonNegative64 = unsafeCoercedecodeNonNegative64 = unsafeCoerceinstanceWord64EncodeIntIntwhereencode64 (x, y) = unsafeCoerce$ (x + 0x3fffffff) .<<. 31 .|. (y + 0x3fffffff)decode64 xy = unsafeCoerce (x, y)where!x = xy .>>. 31 - 0x3fffffff!y = (xy .&. 0x7fffffff) - 0x3fffffffencodeNonNegative64 (x, y) = unsafeCoerce $ x .<<. 31 .|. ydecodeNonNegative64 xy = unsafeCoerce (x, y)where!x = xy .>>. 31!y = xy .&. 0x7fffffffinstanceWord64EncodeIntIntIntwhereencode64 (x, y, z) = unsafeCoerce $ ((x + 0xfffff) .<<. 21 .|. (y + 0xfffff)) .<<. 21 .|. (z + 0xfffff)decode64 xyz = unsafeCoerce (x, y, z)where!x = xyz .>>. 42 - 0xfffff!y = (xyz .>>. 21 .&. 0x1fffff) - 0xfffff!z = xyz .&. 0x1fffff - 0xfffffencodeNonNegative64 (x, y, z) = unsafeCoerce $ (x .<<. 21 .|. y) .<<. 21 .|. zdecodeNonNegative64 xyz = unsafeCoerce (x, y, z)where!x = xyz .>>. 42!y = xyz .>>. 21 .&. 0x1fffff!z = xyz .&. 0x1fffffradixSortInt::VUVectorInt->VUVectorIntradixSortInt = unsafeCoerce . radixSort64 . unsafeCoerceradixSort64::VUVectorWord64->VUVectorWord64radixSort64 vword = F.foldl' step vword [0,16,32,48]wheremask k x = fromIntegral $ x .>>. k .&. 0xffffstep v k = VU.create $ dopref <- VU.unsafeThaw. VU.prescanl' (+) 0. VU.unsafeAccumulate (+) (VU.replicate 0x10000 0)$ VU.map ((, 1) . mask k) vres <- VUM.unsafeNew $ VU.length vVU.forM_ v $ \x -> dolet !masked = mask k xi <- VUM.unsafeRead pref maskedVUM.unsafeWrite pref masked $ i + 1VUM.unsafeWrite res i xreturn resINLINEradixSort::VUUnboxaWord64Encodea=>VUVectora->VUVectoraradixSort = VU.map decode64 . radixSort64 . VU.map encode64INLINEradixSortNonNegative::VUUnboxaWord64Encodea=>VUVectora->VUVectoraradixSortNonNegative= VU.map decodeNonNegative64 . radixSort64 . VU.map encodeNonNegative64INLINEradixSort32::VUVectorWord32->VUVectorWord32radixSort32 vec = F.foldl' step vec [0, 16]wheremask k x = fromIntegral $ x .>>. k .&. 0xffffstep v k = VU.create $ dopref <- VU.unsafeThaw. VU.prescanl' (+) 0. VU.unsafeAccumulate (+) (VU.replicate 0x10000 0)$ VU.map ((, 1) . mask k) vres <- VUM.unsafeNew $ VU.length vVU.forM_ v $ \x -> dolet !masked = mask k xi <- VUM.unsafeRead pref maskedVUM.unsafeWrite pref masked $ i + 1VUM.unsafeWrite res i xreturn resINLINEcompress::VUVectorInt->VUVectorIntcompress vec = VU.create $ domvec <- VUM.unsafeNew (VU.length vec)VU.mapM_ (\(i, x) -> VUM.unsafeWrite mvec (x .&. 0xffffffff) i). VU.postscanl' (\(!i, !x) y ->if x .>>. 32 == y .>>. 32then (i, y)else (i + 1, y)) (-1, -1). radixSortInt$ VU.imap (\i x -> x .<<. 32 .|. i) vecreturn mvecINLINEtype Parser a = StateT BSC8.ByteString Maybe arunParser::Parsera->BSC8ByteString->MaybeaBSC8ByteStringrunParser = runStateTINLINEint::ParserIntint = coerce $ BSC8.readInt . BSC8.dropWhile isSpaceINLINEint1::ParserIntint1 = fmap (subtract 1) intINLINEchar::ParserCharchar = coerce BSC8.unconsINLINEbyte::ParserWord8byte = coerce BS.unconsINLINEskipSpaces::Parser()skipSpaces = modify' (BSC8.dropWhile isSpace)INLINEseqInput::Int->IOVUVectorIntseqInput n = VU.unfoldrN n (runParser int) <$> BSC8.getLineINLINEparseN1::Int->IOVUVectorIntparseN1 n = VU.unfoldrN n (runParser int) <$> BSC8.getContentsINLINEparseN2::Int->IOVUVectorIntIntparseN2 n = VU.unfoldrN n (runParser $ (,) <$> int <*> int) <$> BSC8.getContentsINLINEparseN3::Int->IOVUVectorIntIntIntparseN3 n = VU.unfoldrN n (runParser $ (,,) <$> int <*> int <*> int) <$> BSC8.getContentsINLINEparseN4::Int->IOVUVectorIntIntIntIntparseN4 n = VU.unfoldrN n (runParser $ (,,,) <$> int <*> int <*> int <*> int) <$> BSC8.getContentsINLINEparseN5::Int->IOVUVectorIntIntIntIntIntparseN5 n = VU.unfoldrN n (runParser $ (,,,,) <$> int <*> int <*> int <*> int <*> int) <$> BSC8.getContentsINLINEparseANBN::Int->IOVUVectorIntVUVectorIntparseANBN n = VU.unzip . VU.unfoldrN n (runParser $ (,) <$> int <*> int) <$> BSC8.getContentsINLINEparseANBNCN::Int->IOVUVectorIntVUVectorIntVUVectorIntparseANBNCN n = VU.unzip3 . VU.unfoldrN n (runParser $ (,,) <$> int <*> int <*> int) <$> BSC8.getContentsINLINEreadInt::BSC8ByteString->IntreadInt = fst . fromJust . BSC8.readIntINLINEgetInt::IOIntgetInt = readInt <$> BSC8.getLineINLINEreadIntList::BSC8ByteString->IntreadIntList = map readInt . BSC8.wordsINLINEgetIntList::IOIntgetIntList = readIntList <$> BSC8.getLineINLINEreadInteger::BSC8ByteString->IntegerreadInteger = fst . fromJust . BSC8.readIntegerINLINEgetInteger::IOIntegergetInteger = readInteger <$> BSC8.getLineINLINEreadIntegerList::BSC8ByteString->IntegerreadIntegerList = map readInteger . BSC8.wordsINLINEgetIntegerList::IOIntegergetIntegerList = readIntegerList <$> BSC8.getLineINLINE