Coin Collecting 2
InterviewTime limit2sMemory limit1024 MB
Aoi flips one row and Rin flips one column, each trying to collect more coins. Find both players' counts under optimal play.
- Level
Medium4 of 10
- Topics
- Math, Brute force, Implementation
- Solved
- No attempts yet
Problem
On the desk, coins are arranged in a rectangle with rows and columns. Initially, the coin in row from the top () and column from the left () shows its front side if #, and its back side if ..
Aoi and Rin play a game with these coins. The game proceeds as follows.
- Aoi chooses one row and flips all coins in that row.
- Rin chooses one column and flips all coins in that column.
- Aoi collects all coins showing front sides. Rin collects all coins showing back sides.
Each of them wants to collect as many coins as possible.
Given the initial state of the coins, write a program that finds how many coins each player collects when both play optimally.
Input
The input is given in the following format.
H W
S1,1 S1,2 … S1,W
S2,1 S2,2 … S2,W
︙
SH,1 SH,2 … SH,W
Output
Print Aoi's score and Rin's score in this order, separated by a space.
Constraints
- .
- .
- .
- Each is either
#or.(, ). - and are integers.