Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 11;
- int arr[N][N], row[N], col[N], diag[3];
- int main()
- {
- int n;
- scanf("%d", &n);
- bool fail = false;
- set<int> used;
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- scanf("%d", &arr[i][j]);
- if (arr[i][j] > n*n || used.count(arr[i][j]) > 0)
- fail = true;
- used.insert(arr[i][j]);
- row[i] += arr[i][j];
- col[j] += arr[i][j];
- if (i == j)
- diag[0] += arr[i][j];
- if (i+j == n-1)
- diag[1] += arr[i][j];
- }
- if (row[i] != row[0])
- fail = true;
- }
- for (int j = 0; j < n; ++j) {
- if (col[j] != row[0])
- fail = true;
- }
- if (diag[0] != diag[1] || diag[0] != row[0])
- fail = true;
- if (fail)
- printf("No\n");
- else
- printf("Yes\n");
- return 0;
- }
Add Comment
Please, Sign In to add comment