Guest User

Untitled

a guest
Nov 5th, 2021
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Data.List ( group, sort, transpose )
  2. import GHC.Base (join)
  3. import Control.Arrow ( Arrow((&&&)) )
  4. import Data.Traversable (for)
  5. import Control.Monad (replicateM)
  6. import Data.Char ( digitToInt )
  7. f a= map $ join.map (\x->[length x:head x] <> replicate (length x - 1) [0]).group.a
  8. f2 x= map (length &&& head).group.sort.map (reverse.sort.init).filter ((/=0).last).join.f id $ transpose $ f (map (:[])) x
  9. ff n = replicateM n getLine
  10. main = do
  11.     x <- getLine
  12.     matr <- ff (read $ takeWhile (/=' ') x )
  13.     print $ f2 $ (map.map) digitToInt matr
Advertisement
Add Comment
Please, Sign In to add comment