Juno hates birds!!
Time limit2sMemory limit256 MB
Given an n by m grid of numbers, remove the row or column containing the most digit 9s (ties broken by scanning order) and count the remaining 9s.
- Level
Medium4 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Problem
Juno hates birds, and he hates pigeons most of all.
During class Juno and the classmate sitting next to him decided to play bingo. Each of them wrote the numbers they wanted on an bingo board, and then they swapped boards. As soon as Juno looked at his partner's board he got angry, because so many of the numbers contained the digit 9 that he started thinking about pigeons. So he decided to smash the board.
His rampage follows one rule. Among all rows and all columns, he picks exactly one row or column that holds the digit 9 the most times, and smashes every cell in it.
Nines are counted digit by digit, not cell by cell. A cell holding 999 has three nines, and a cell holding 90 has one.
The moment the board broke, the teacher looked straight at Juno and decided to hit him once for every 9 still on the board. How many times does Juno get hit?
Input
The first line contains the board size and (, ).
Each of the next lines contains numbers separated by spaces. Every number written on the board is a non-negative integer not greater than 10,000.
Output
Print the number of hits Juno takes, which is the number of nines left on the board after one row or one column is smashed.