Advertisement
Ankit_132

B

Apr 8th, 2024
1,092
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll     long long
  6. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  7. #define pb     push_back
  8. #define ppb    pop_back
  9. #define pf     push_front
  10. #define ppf    pop_front
  11.  
  12. int main()
  13. {
  14.     _test
  15.     {
  16.         int n, c, d;
  17.         cin>>n>>c>>d;
  18.  
  19.         vector<int> a(n*n);
  20.  
  21.         for(auto &e: a)
  22.             cin>>e;
  23.  
  24.         int x = *min_element(a.begin(), a.end());
  25.  
  26.         vector<vector<int>> tmp(n, vector<int> (n));
  27.  
  28.         tmp[0][0] = x;
  29.  
  30.         for(int j=0; j<n-1; j++)
  31.             tmp[0][j+1] = tmp[0][j] + d;
  32.  
  33.         for(int i=0; i<n-1; i++)
  34.         {
  35.             for(int j=0; j<n; j++)
  36.                 tmp[i+1][j] = tmp[i][j] + c;
  37.         }
  38.  
  39.         vector<int> b;
  40.  
  41.         for(int i=0; i<n; i++)
  42.         {
  43.             for(int j=0; j<n; j++)
  44.                 b.pb(tmp[i][j]);
  45.         }
  46.  
  47.         sort(a.begin(), a.end());
  48.         sort(b.begin(), b.end());
  49.  
  50.         if(a == b)      cout<<"YES\n";
  51.         else            cout<<"NO\n";
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement