blob: 95290b79b6e360f1eb73b9c49037f371be50d542 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
// 1071. Number Spiral
#include <bits/stdc++.h>
using namespace std;
long long x, y;
long long solve(long long x, long long y) {
long long z = fmax(x, y) - 1;
if (z & 1)
return x < y ? z * z + x : z * z + 2 * z - y + 2;
else
return x < y ? z * z + 2 * z - x + 2 : z * z + y;
}
int main() {
static int tmp;
scanf("%d", &tmp);
for (int i = 0; i < tmp; i++) {
scanf("%lld %lld", &x, &y);
printf("%lld\n", solve(x, y));
}
}
|