Advertisement
Saleh127

CF 1422B

Oct 5th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);
  9. cout.tie(0);
  10.  
  11. test
  12. {
  13. ll a[105][105],c,d,e,f,r,i,j,k,l,m,n;
  14. cin>>r>>c;
  15.  
  16. for(i=1; i<=r; i++)
  17. {
  18. for(j=1; j<=c; j++)
  19. {
  20. cin>>a[i][j];
  21. }
  22. }
  23. l=0;
  24.  
  25. for(i=1; i<=(r+1)/2; i++)
  26. {
  27. for(j=1; j<=(c+1)/2; j++)
  28. {
  29. vector<ll>x;
  30.  
  31. m=r+1-i;
  32. n=c+1-j;
  33.  
  34. x.push_back(a[i][j]);
  35.  
  36. if(m!=i) x.push_back(a[m][j]);
  37. if(n!=j) x.push_back(a[i][n]);
  38. if(m!=i && n!=j) x.push_back(a[m][n]);
  39.  
  40. sort(x.begin(),x.end());
  41.  
  42. if(x.size()==2) l+=x[1]-x[0];
  43. else if(x.size()==4) l+=x[3]+x[2]-x[1]-x[0];
  44. }
  45. }
  46. cout<<l<<endl;
  47. }
  48. return 0;
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement