Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 10;
- const int N2 = N * N;
- int board[N + 10][N + 10];
- bool found[N2 + 10];
- int main(){
- int n;
- scanf("%d", &n);
- int crossSumL = 0;
- int crossSumR = 0;
- int lastSum;
- for(int i = 1; i <= n; ++i){
- int rowSum = 0;
- for(int j = 1; j <= n; ++j){
- scanf("%d", &board[i][j]);
- found[board[i][j]] = true;
- rowSum += board[i][j];
- if(i == j){
- crossSumR += board[i][j];
- }
- if(i + j == n + 1){
- crossSumL += board[i][j];
- }
- }
- if(i == 1){
- lastSum = rowSum;
- } else if(rowSum != lastSum){
- cout << "No";
- return 0;
- }
- }
- if(!(crossSumL == crossSumR && crossSumL == lastSum)){
- cout << "No";
- return 0;
- }
- for(int i = 1; i <= n; ++i){
- int colSum = 0;
- for(int j = 1; j <= n; ++j){
- colSum += board[j][i];
- }
- if(colSum != lastSum){
- cout << "No";
- return 0;
- }
- }
- int n2 = n * n;
- for(int i = 1; i <= n2; ++i){
- if(!found[i]){
- cout << "No";
- return 0;
- }
- }
- cout << "Yes";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement