Skip to content

raydsameshima/HaskellPlayground

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 

Repository files navigation

HaskellPlayground

Experiments of Haskell programming, especially AtCoder.

See A good reference in Japanse

AtCoder Beginners Selection

See, totemo kawaii.

IO

String = [Char] is too slow.

Data.ByteString.Char8

See the discussion in Data.Text vs Data.ByteString.Char8

Instead of using

main = do
  as <- map read . words <$> getLine
  ...

we must use Data.ByteString.Char8:

import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )

readInt :: IO Int
readInt = fst . fromJust . C.readInt <$> C.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main = do
  as <- readInts
  ...

GHC language extensions

A good start wll be here.

http://fumieval.hatenablog.com/entry/2015/12/10/200630

strict flag

BangPattern

TBA

Usefull links

Category Theory for Programmers

Category Theory for Programmers: The Preface

10 types of problems

See, again A good reference in Japanse

ABC 086 A - Product

abc086_a

Mod, or rem.

For non-negative integers, use rem. (see https://twitter.com/mod_poppo/status/1092144670526791680)

Related problems

abc064_a

abc088_a

abc082_a

Note

As a common technique, e.g., if we want to calculate the round up the mean of a,b :: Int,

  (a+b+1) `div` 2

that is, we do not need to write like

  kiriage a b
    | even (a+b) = (a+b)   `div` 2
    | otherwise  = (a+b+1) `div` 2 

ABC 081 A - Placing Marbles

abc081_a

Brute-force search.

Related problems

abc095_a

abc085_a

abc069_b

abc082_b

ABC 081 B - Shift Only

abc081_b

For loop

Related problems

abc068_b

abc102_b Data.ByteString.Char8

abc113_b Data.ByteString.Char8

We have the following O(n) (not O(2*n)) maxMin,

maxMin :: [Int] -> (Int, Int)
maxMin = (,) <$> maximum <*> minimum

abc072_b It is interesting but the raw recursion is faster and cheaper.

abc053_b Data.ByteString.Char8

abc095_b

ABC 087 B - Coins

abc087_b

Dynamic Programming (DP) algorithm

How is Dynamic programming different from Brute force

Related problems

abc105_b

arc004_1

abc051_b

ABC083 B - Some Sums

abc083_b

Integers (decimal numbers) and for loop.

Related problems

abc080_b

abc090_b

agc025_a Vector performs well. Indeed, the interface is easy and clear.

ABC 088 B - Card Game for Two

Sorts, Greedy

Related problems

abc067_b

abc042_b Data.ByteString.Char8

agc027_a Data.ByteString.Char8

agc012_a Data.ByteString.Char8

ABC 085 B - Kagami Mochi

abc085_b Data.ByteString.Char8

Related problems

abc071_b Data.ByteString.Char8

abc061_b Data.ByteString.Char8

abc091_b Data.ByteString.Char8

arc086_a Data.ByteString.Char8

Note: my implementation uses only List as the data structure. The execution time is so far beyond ok line, but some additional factor may be earned.

By the way, why this link is not self-consistent? I mean, the title after constests in its url differs from the last arc086_a.

ABC 085 C - Otoshidama

abc085_c

Double, or triple folded for-loops (still eager search)

Initial attempt was using list comprehension to filter a correct combination. It basically the same as double-for-loops as in https://qiita.com/drken/items/fd4e5e3630d0f5859067#第-8-問--abc-085-c---otoshidama-300-点

Second attempt is much faster; first construct the ideal combination to pay Y-yen, maximumizing 10000-bills, then exchanging into smaller bill to reach the given N-bills.

Related problems

abc088_c Data.ByteString.Char8

We do not need to find a solution, but to say the existance. Probably, it's a good time to study data structures.

arc096_a Data.ByteString.Char8

Simple comparison.

abc057_c Data.ByteString.Char8

Prime factors. It requires factor 2 in execution time and memory usage.

arc083_a Data.ByteString.Char8

Need better implementation, say factor 3. Filter has to be done only once.

About

Haskell Experiments

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages