AquaBlitz11

TASK_053 - ChimengSoso's Solution

Jan 7th, 2018
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. const int N = 12;
  4.  
  5. int sr[N], sc[N], d1, d2;
  6. bool cnt[N*N];
  7.  
  8. int main() {
  9.     int n;
  10.     scanf("%d", &n);
  11.     for (int i = 0; i < n; ++i) {
  12.         for (int j = 0; j < n; ++j) {
  13.             int x;
  14.             scanf("%d", &x);
  15.            
  16.             if (i == j)     d1 += x;
  17.             if (i+j == n-1) d2 += x;
  18.             sr[i] += x;
  19.             sc[j] += x;
  20.             cnt[x] = true;
  21.         }
  22.     }
  23.     for (int i = 1; i <= n*n; ++i)
  24.         if (cnt[i] == false) return printf("No\n"), 0;
  25.    
  26.     for (int i = 0; i < n-1; ++i)
  27.         if (sr[i] != sr[i+1] or sc[i] != sc[i+1]  or sr[i] != sc[i] or d1 != d2 or d1 != sr[i])
  28.             return printf("No\n"), 0;
  29.    
  30.     printf("Yes\n");
  31.     return 0;
  32. }
Add Comment
Please, Sign In to add comment