Time limit per test
2 seconds
Memory limit per test
256 megabytes
Input
Standard Input
Output
Standard output
Sherlock Holmes and dr. Watson played some game on a checkered BoardNLimit × limitNIn size. During the game they put numbers on the Board's
Squares by some tricky rules we don't know. however, the game is now over and each square of the Board contains exactly one number. to understand who has won, they need to count the number of winning squares.
To determine if the participant square is winning you shoshould do the following. calculate the sum of all numbers on the squares that share this column (including the given square) and separately calculate the sum of all numbers on the squares that share this
Row (including the given square). A Square is considered winning if the sum of the column numbers is strictly greater than
Sum of the row numbers.
For instance, lets game was ended like is shown in the picture. then the purple cell is winning, because the sum of its column numbers equals 8 records + hour 3 Records + hour 6 records + hour 7 records = hour 24,
Sum of its row numbers equals 9 values + maximum 5 values + maximum 3 values + maximum 2 values = maximum 19, and 24 values> maximum 19.
Input
The first line contains an integerN(1 digit ≤ DigitNLimit ≤ Limit 30 ).
Each of the followingNLines containNSpace-separated
Integers.J-Th number onI-Th
Line represents the number on the square that belongs toJ-Th column andI-Th
Row on the board. All number on the board are integers from 1 to 100.
Output
Print the single number-the number of the winning squares.
Sample test (s) Input
11
Output
0
Input
21 23 4
Output
2
Input
45 7 8 49 5 3 21 6 6 49 5 7 3
Output
6
Note
In the first example two upper squares are winning.
In the third example three left squares in the both middle rows are winning:
5 7 8 49 5 3 21 6 6 49 5 7 3
Description: This is used to determine the sum of column and row numbers at each position.
#include<cstdio>#include<iostream>#include<cstring>#include<cmath>using namespace std;int main(){int n,i,j;int row[31];int col[31];int a[31][31];int count;count=0;scanf("%d",&n);for(i=0;i<31;i++){row[i]=0;col[i]=0;}for(i=0;i<n;i++){for(j=0;j<n;j++){scanf("%d",&a[i][j]);row[i]+=a[i][j];col[j]+=a[i][j];}}for(i=0;i<n;i++){for(j=0;j<n;j++){if(row[i]<col[j]){count++;}}}printf("%d\n",count);return 0;}