Diagonal Dominance
Time limit2sMemory limit1024 MB
Given an n by n matrix of nonnegative integers, check whether it is diagonally dominant and count the strictly dominant diagonal elements.
- Level
Easy2 of 10
- Topics
- Matrix, Implementation
- Solved
- No attempts yet
Problem
Macrohard studies diagonally dominant matrices, which are needed to write their new operating system Doors 8. An matrix is called a diagonally dominant matrix if all three of the following conditions hold:
- There exists an such that
A diagonal element is called dominant if
Until recently, the Macrohard staff checked matrices by hand with a calculator. Yesterday they went on strike, because they were tired of doing the same operations on large matrices. The Macrohard chief hired you to write a program that automates their tedious calculations. Don't make a mistake!
Input
The first line contains an integer (), the size of the matrix. Each of the next lines contains integers, the elements of the matrix ().
Output
If the matrix is a "beautiful" matrix, print "YES". Otherwise, print "NO". If the matrix is diagonally dominant, print the number of dominant elements on the next line.