結果
問題 | No.998 Four Integers |
ユーザー | こまる |
提出日時 | 2020-10-31 11:45:32 |
言語 | Haskell (9.8.2) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,121 bytes |
コンパイル時間 | 5,928 ms |
コンパイル使用メモリ | 213,760 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-22 04:48:59 |
合計ジャッジ時間 | 5,863 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 2 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | WA | - |
コンパイルメッセージ
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
ソースコード
{-# LANGUAGE BangPatterns #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE TupleSections #-} module Main where import Control.Monad import Control.Monad.Fix import Control.Monad.ST import Control.Monad.State import Data.Bits import Data.Bool import Data.Char import Data.Coerce import qualified Data.Foldable as F import Data.Word import Unsafe.Coerce import qualified Data.ByteString.Char8 as BSC8 import qualified Data.Vector.Fusion.Stream.Monadic as VFSM import qualified Data.Vector.Generic as VG import qualified Data.Vector.Generic.Mutable as VGM import qualified Data.Vector.Unboxed as VU import qualified Data.Vector.Unboxed.Mutable as VUM main :: IO () main = do xs <- seqInput 4 putStrLn $ bool "No" "Yes" (solve xs) solve :: VU.Vector Int -> Bool solve xs = runST $ do let ys = stoogeSort xs a = ys VU.! 0 b = ys VU.! 1 c = ys VU.! 2 d = ys VU.! 3 return ((a + 1 == b) && (b + 1 == c) && (c + 1 == d)) 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 #-} seqInput :: Int -> IO (VU.Vector Int) seqInput n = VU.unfoldrN n (runCParser int) <$> BSC8.getLine {-# INLINE seqInput #-} stoogeSort :: (Ord a, VG.Vector v a) => v a -> v a stoogeSort = stoogeSortBy compare stoogeSortBy :: (Ord a, VG.Vector v a) => (a -> a -> Ordering) -> v a -> v a stoogeSortBy cmp = VG.modify $ fix $ \loop vec -> do item1 <- VGM.unsafeRead vec 0 item2 <- VGM.unsafeRead vec (VGM.length vec - 1) when (cmp item1 item2 == LT) $ VGM.unsafeSwap vec 0 (VGM.length vec - 1) when (VGM.length vec > 2) $ do loop (VGM.unsafeDrop (VGM.length vec `div` 3) vec) loop (VGM.unsafeTake ((VGM.length vec `div` 3) * 2) vec) loop (VGM.unsafeDrop (VGM.length vec `div` 3) vec) {-# INLINE stoogeSortBy #-}