結果

問題 No.1232 2^x = x
ユーザー こまるこまる
提出日時 2020-10-23 10:42:45
言語 Haskell
(9.8.2)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,365 bytes
コンパイル時間 4,831 ms
コンパイル使用メモリ 199,904 KB
実行使用メモリ 9,828 KB
最終ジャッジ日時 2023-09-28 15:15:09
合計ジャッジ時間 5,672 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,536 KB
testcase_01 AC 3 ms
8,676 KB
testcase_02 AC 5 ms
9,828 KB
testcase_03 AC 5 ms
9,640 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State               (StateT (..), modify')
import           Data.Char                         (isSpace)
import           Data.Coerce                       (coerce)
import           Data.Word                         (Word8)
import qualified Data.ByteString                   as BS
import qualified Data.ByteString.Char8             as BSC8
import qualified Data.Vector.Unboxed               as VU

main :: IO ()
main = do
  n  <- readLn :: IO Int
  ps <- parseN1 n
  putStr . unlines . map show . VU.toList $ solver ps

solver :: VU.Vector Int -> VU.Vector Int
solver qs = runST $ VU.forM qs $ \p -> if p == 1 then return 2 else return $ p * p 

-------------------------------------------------------------------------------
-- Input
-------------------------------------------------------------------------------

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 #-}
int1 :: CParser Int
int1 = fmap (subtract 1) int
{-# INLINE int1 #-}
parseN1 :: Int -> IO (VU.Vector Int)
parseN1 n = VU.unfoldrN n (runCParser int1) <$> BSC8.getContents
{-# INLINE parseN1 #-}
0