fork download
  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, forM_)
  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. forM_ (f2 $ (map.map) digitToInt matr) $ \(x, [a, b]) ->
  14. putStrLn $ show a ++ " " ++ show b ++ " " ++ show x
Success #stdin #stdout 0s 5680KB
stdin
6 10
0111000011
0000011011
0100011000
0101011011
0100000000
0001111011
stdout
1 1 1
2 1 2
2 2 1
3 1 2
3 2 1
4 1 1