LoginSignup
2
0

More than 3 years have passed since last update.

Haskell競技プログラミング用メモ

Last updated at Posted at 2020-08-16

文字列

Data.ByteString.Chan8

Data.Vector.Unboxed

create, unfoldrN, fusion

Data.Vector.Unboxed.Mutable

new, read, modify, write, freeze, thaw

データ構造

priority queue → Data.Set
グラフの構築やdfs → Data.Graph

再帰

foldl',foldr(早期リターン)

Prelude

IO

a1-an読み込み

import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B

main = do
  let readInt = fmap (second B.tail) . B.readInt

  as <- VU.unfoldrN n readInt <$> B.getLine
ABを読み取り

import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B

main = do
  let readInt = fmap (second B.tail) . B.readInt

  (a,b) <- (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
A1B1A2B2...AnBn

import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B

main = do
  let readInt = fmap (second B.tail) . B.readInt

  abs <-
    VU.replicateM n $ (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
IOまとめ
readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

パフォーマンスの目安

実行時間はC++の5倍以内を目指す

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0