Advertisement
Korotkodul

CF now

Jan 15th, 2022
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. #define vec vector
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17. for (auto x: v) cout<<x<<' ';
  18. cout<<"\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v){
  22. for (auto x: v) cout<<x<<' ';
  23. cout<<"\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v){
  28. for (auto x: v) cv(x);
  29. cout<<"\n";
  30. }
  31. pii md;
  32.  
  33. int dst(pii a, pii b){
  34. return abs(a.first - b.first) + abs(a.second - b.second);
  35. }
  36.  
  37. bool cmp1(pii a, pii b){
  38. return dst(a, md) < dst(b, md);
  39. }
  40.  
  41. bool cmp2(pii a, pii b){
  42. return dst(a, md) > dst(b, md);
  43. }
  44. int main()
  45. {
  46. ios::sync_with_stdio(0);
  47. cin.tie(0);
  48. cout.tie(0);
  49. int t,n,m; cin>>t;
  50. vector <pii> R;
  51. vector <int> ans;
  52. vector <pii> T;
  53. for (int act=0;act<t;++act){
  54. cin>>n>>m;
  55. for (int i = 0; i < n; ++i){
  56. for (int j = 0;j<m;++j){
  57. R.push_back({i, j});
  58. }
  59. }
  60. md = {n / 2, m / 2};
  61. sort(R.begin(), R.end(), cmp1);
  62. T = R;
  63. sort(T.begin(), T.end(), cmp2);
  64. ans.resize(n*m);
  65. for (int i=0;i<n*m;++i){
  66. ans[i] = dst(T[i], R[i]);
  67. }
  68. cv(ans);
  69. }
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement