#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const int maxn5 = 1e5 + 10;
const int inf = 1e9;
const int mod = 1e9 + 7;
const ll mod10 = 10000000070;
inline ll get(ll x, ll y){
if(x == 0 && y == 0)
return 1;
if(x >= 0 && y < 0){
if(x == -y)
return ((2 * x + 1) % mod) * ((2 * x + 1) % mod) % mod;
if(x < -y)
return (mod10 + get(-y, y) - ((mod10 + -y - x) % mod)) % mod;
return (get(x - 1, x - 1) + 1 + x + y + mod10) % mod;
}
if(x < 0 && y <= 0){
if(x == y)
return (get(-x, y) + 2 * x + mod10) % mod;
if(x < y)
return (get(x, x) - (-x + y) + mod10) % mod;
return (get(y, y) + (-y + x) + mod10) % mod;
}
if(x <= 0 && y > 0){
if(-x == y)
return (get(x, x) + 2 * x + mod10) % mod;
if(-x > y)
return (get(x, -x) + (-x - y) + mod10) % mod;
return (get(-y, y) - (y + x) + mod10) % mod;
}
if(x > 0 && y >= 0){
if(x == y)
return (get(-x, x) - 2 * x + mod10) % mod;
if(x < y)
return (get(y, y) + y - x + mod10) % mod;
return (get(x, x) - (x - y) + mod10) % mod;
}
cout << "WTF " << endl;
cout << 1 / 0 << endl;
return -1;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n, q; cin >> n >> q;
while(q--){
ll x, y; cin >> x >> y >> x >> y;
cout << get(x, y) % mod << '\n';
}
}
Compilation message
spiral.cpp: In function 'll get(ll, ll)':
spiral.cpp:50:15: warning: division by zero [-Wdiv-by-zero]
50 | cout << 1 / 0 << endl;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |