結果
| 問題 |
No.1232 2^x = x
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-23 10:42:45 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,365 bytes |
| コンパイル時間 | 6,651 ms |
| コンパイル使用メモリ | 208,660 KB |
| 実行使用メモリ | 6,016 KB |
| 最終ジャッジ日時 | 2024-07-21 09:57:05 |
| 合計ジャッジ時間 | 7,287 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 3 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking a.out
ソースコード
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 #-}