結果

問題 No.1185 完全な3の倍数
ユーザー こまるこまる
提出日時 2020-10-18 22:28:28
言語 Haskell
(9.8.2)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,331 bytes
コンパイル時間 5,250 ms
コンパイル使用メモリ 294,428 KB
実行使用メモリ 11,260 KB
最終ジャッジ日時 2023-09-28 12:08:43
合計ジャッジ時間 7,193 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
11,072 KB
testcase_01 AC 12 ms
11,032 KB
testcase_02 AC 12 ms
11,216 KB
testcase_03 AC 12 ms
11,144 KB
testcase_04 AC 12 ms
11,092 KB
testcase_05 AC 12 ms
11,032 KB
testcase_06 AC 11 ms
11,080 KB
testcase_07 AC 12 ms
11,076 KB
testcase_08 AC 12 ms
11,156 KB
testcase_09 AC 12 ms
11,056 KB
testcase_10 AC 12 ms
11,148 KB
testcase_11 AC 12 ms
11,116 KB
testcase_12 AC 12 ms
11,032 KB
testcase_13 AC 12 ms
11,156 KB
testcase_14 AC 12 ms
11,188 KB
testcase_15 AC 12 ms
11,168 KB
testcase_16 AC 12 ms
11,068 KB
testcase_17 AC 12 ms
11,072 KB
testcase_18 AC 12 ms
11,164 KB
testcase_19 AC 12 ms
11,184 KB
testcase_20 AC 12 ms
11,152 KB
testcase_21 AC 12 ms
11,184 KB
testcase_22 AC 12 ms
11,052 KB
testcase_23 AC 12 ms
11,160 KB
testcase_24 AC 12 ms
11,260 KB
testcase_25 AC 12 ms
11,140 KB
testcase_26 AC 12 ms
11,120 KB
testcase_27 AC 12 ms
11,072 KB
testcase_28 AC 12 ms
11,044 KB
testcase_29 AC 12 ms
11,188 KB
testcase_30 AC 12 ms
11,076 KB
testcase_31 AC 12 ms
11,068 KB
testcase_32 AC 12 ms
11,108 KB
testcase_33 AC 12 ms
11,156 KB
testcase_34 AC 12 ms
11,108 KB
testcase_35 AC 12 ms
11,092 KB
testcase_36 AC 12 ms
11,188 KB
testcase_37 AC 12 ms
11,076 KB
testcase_38 AC 12 ms
11,032 KB
testcase_39 AC 12 ms
11,156 KB
testcase_40 AC 12 ms
11,208 KB
testcase_41 AC 12 ms
11,152 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 #

{-# LANGUAGE BangPatterns #-}
import           Control.Monad
import           Data.IORef
import qualified Data.Vector.Fusion.Stream.Monadic as VFSM
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 #-}
r09 :: Monad m => (Int -> m ()) -> m ()
r09 = flip VFSM.mapM_ (stream 0 10)
{-# INLINE r09 #-}
r19 :: Monad m => (Int -> m ()) -> m ()
r19 = flip VFSM.mapM_ (stream 1 10)
{-# INLINE r19 #-}
r03 :: Monad m => (Int -> m ()) -> m ()
r03 = flip VFSM.mapM_ (stream 0 4)
{-# INLINE r03#-}
main :: IO ()
main = do
  n   <- readLn :: IO Int
  ans <- newIORef (0 :: Int)
  tmp <- newIORef (0 :: Int)
  r19 $ \i -> r09 $ \j -> do
    writeIORef tmp (i * 10 + j)
    temp <- readIORef tmp
    when (temp <= n && temp `mod` 3 == 0) $ modifyIORef' ans succ
  r03 $ \i0 -> r03 $ \i1 -> r03 $ \i2 -> r03 $ \i3 -> r03 $ \i4 -> r03 $ \i5 -> r03 $ \i6 -> r03 $ \i7 -> r03 $ \i8 -> do
    writeIORef tmp (i0 + i1 * 10 + i2 * 100 + i3 * 1000 + i4 * 10000 + i5 * 100000 + i6 * 1000000 + i7 * 10000000 + i8 * 100000000)
    modifyIORef' tmp (*3)
    temp <- readIORef tmp
    when (temp <= n && temp > 100) $ modifyIORef' ans succ
  print =<< readIORef ans
0