Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- pii md;
- int dst(pii a, pii b){
- return abs(a.first - b.first) + abs(a.second - b.second);
- }
- bool cmp1(pii a, pii b){
- return dst(a, md) < dst(b, md);
- }
- bool cmp2(pii a, pii b){
- return dst(a, md) > dst(b, md);
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int t,n,m; cin>>t;
- vector <pii> R;
- vector <int> ans;
- vector <pii> T;
- for (int act=0;act<t;++act){
- cin>>n>>m;
- for (int i = 0; i < n; ++i){
- for (int j = 0;j<m;++j){
- R.push_back({i, j});
- }
- }
- md = {n / 2, m / 2};
- sort(R.begin(), R.end(), cmp1);
- T = R;
- sort(T.begin(), T.end(), cmp2);
- ans.resize(n*m);
- for (int i=0;i<n*m;++i){
- ans[i] = dst(T[i], R[i]);
- }
- cv(ans);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement