You are viewing a single comment's thread. Return to all comments →
Haskell:
module Main where import Control.Monad (replicateM, replicateM_) import Data.List (sort, transpose) rowsums :: [[Integer]] -> [Integer] rowsums = map sum colsums :: [[Integer]] -> [Integer] colsums rows = map sum (transpose rows) testsums :: [[Integer]] -> Bool testsums rows = sort (rowsums rows) == sort (colsums rows) main :: IO () main = do cases <- readLn :: IO Int replicateM_ cases $ do n <- readLn :: IO Int rows <- replicateM n $ map read . words <$> getLine :: IO [[Integer]] putStrLn $ if testsums rows then "Possible" else "Impossible"
Seems like cookies are disabled on this browser, please enable them to open this website
Organizing Containers of Balls
You are viewing a single comment's thread. Return to all comments →
Haskell: