AquaBlitz11

TASK_053 - AquaBlitz11's Solution

Jan 7th, 2018
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 11;
  6.  
  7. int arr[N][N], row[N], col[N], diag[3];
  8.  
  9. int main()
  10. {
  11.     int n;
  12.     scanf("%d", &n);
  13.  
  14.     bool fail = false;
  15.     set<int> used;
  16.     for (int i = 0; i < n; ++i) {
  17.         for (int j = 0; j < n; ++j) {
  18.             scanf("%d", &arr[i][j]);
  19.             if (arr[i][j] > n*n || used.count(arr[i][j]) > 0)
  20.                 fail = true;
  21.             used.insert(arr[i][j]);
  22.             row[i] += arr[i][j];
  23.             col[j] += arr[i][j];
  24.             if (i == j)
  25.                 diag[0] += arr[i][j];
  26.             if (i+j == n-1)
  27.                 diag[1] += arr[i][j];
  28.         }
  29.         if (row[i] != row[0])
  30.             fail = true;
  31.     }
  32.     for (int j = 0; j < n; ++j) {
  33.         if (col[j] != row[0])
  34.             fail = true;
  35.     }
  36.     if (diag[0] != diag[1] || diag[0] != row[0])
  37.         fail = true;
  38.  
  39.     if (fail)
  40.         printf("No\n");
  41.     else
  42.         printf("Yes\n");
  43.  
  44.     return 0;
  45. }
Add Comment
Please, Sign In to add comment