Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- const int N = 12;
- int sr[N], sc[N], d1, d2;
- bool cnt[N*N];
- int main() {
- int n;
- scanf("%d", &n);
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- int x;
- scanf("%d", &x);
- if (i == j) d1 += x;
- if (i+j == n-1) d2 += x;
- sr[i] += x;
- sc[j] += x;
- cnt[x] = true;
- }
- }
- for (int i = 1; i <= n*n; ++i)
- if (cnt[i] == false) return printf("No\n"), 0;
- for (int i = 0; i < n-1; ++i)
- if (sr[i] != sr[i+1] or sc[i] != sc[i+1] or sr[i] != sc[i] or d1 != d2 or d1 != sr[i])
- return printf("No\n"), 0;
- printf("Yes\n");
- return 0;
- }
Add Comment
Please, Sign In to add comment