Last active
August 29, 2015 14:09
-
-
Save m-renaud/d686d597eca822b857ee to your computer and use it in GitHub Desktop.
Reading lots of input.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | Timing breakdown: | |
-- Reading: 2.5s | |
-- Sorting: 3.5s | |
module Main where | |
import Control.Applicative | |
import Control.Monad | |
import Data.ByteString.Char8 (pack) | |
import Data.Attoparsec.ByteString.Char8 | |
import Data.Functor | |
import Data.List | |
doLinearTimeStuffWith :: Int -> [Int] -> IO () | |
doLinearTimeStuffWith n ns = print (ns !! (n - 1)) | |
parseIntList :: Int -> Parser [Int] | |
parseIntList n = count n (signed decimal <* endOfLine) | |
main = do | |
n <- readLn :: IO Int | |
ns <- parseOnly (parseIntList n) . pack <$> getContents | |
case ns of | |
Left err -> print err | |
Right ns' -> doLinearTimeStuffWith n $ sort ns' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Control.Monad | |
import Data.List | |
doLinearTimeStuffWith :: Int -> [Int] -> IO () | |
doLinearTimeStuffWith n ns = print (ns !! (n - 1)) | |
main = do | |
n <- readLn :: IO Int | |
ns <- replicateM n (readLn :: IO Int) | |
doLinearTimeStuffWith n $ sort ns |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment