-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathb.cc
36 lines (34 loc) · 826 Bytes
/
b.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// https://codeforces.com/contest/1627/problem/B
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
cin.tie(0), ios::sync_with_stdio(0);
ll t, n, m;
cin >> t;
while (t--) {
cin >> n >> m;
ll k = (n + 1) / 2 + (m + 1) / 2 - 1;
string sep = "";
int c = 0;
for (ll i = 0; i < k; i++) {
ll j = min(i, k - (i + 1)) + 1;
ll r = min(j, min((m + 1) / 2, (n + 1) / 2)) * 4;
if (!i) {
if (n % 2 && m % 2) r = 1;
else if (n % 2 || m % 2)
r = 2;
} else {
if (i < (m + 1) / 2 && n % 2) r -= 2;
if (i < (n + 1) / 2 && m % 2) r -= 2;
}
c += r;
for (int l = 0; l < r; l++) {
cout << sep << n / 2 + m / 2 + i;
sep = " ";
}
}
assert(c == n * m);
cout << '\n';
}
}