#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
const int inf = int(1e18);
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> p2;
#define rep(i, high) for (int i = 0; i < high; i++)
#define repp(i, low, high) for (int i = low; i < high; i++)
#define repe(i, container) for (auto& i : container)
#define sz(container) ((int)container.size())
#define all(x) begin(x),end(x)
#define ceildiv(x,y) ((x + y - 1) / (y))
inline void fast() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
#define _LOCAL _DEBUG
#if _LOCAL
#define assert(x) if (!(x)) __debugbreak()
#endif
int n;
int getv(int a, int b)
{
//a -= n;
//b -= n;
int layer = max(abs(a), abs(b));
int layerv = (layer * 2 + 1) * (layer * 2 + 1);
p2 layerbr = p2(layer, layer);
if (p2(a, b) == layerbr)
{
return layerv;
}
if (a == layerbr.first)
{
return layerv - (layerbr.second - b);
}
if (a == layerbr.first - layer * 2)
{
return layerv - layer * 6 - (b - layerbr.second);
}
p2 layerbl = p2(layer, -layer);
if (b == layerbl.second)
{
return layerv - layer * 2 - (layerbl.first - a);
}
if (b == layerbl.second + layer * 2)
{
return layerv - layer * 8 - (a - layerbl.first);
}
return layer;
};
int eval(vvi poly)
{
return 0;
}
vvi cache(100, vi(100, -1));
int sum(int a, int b)
{
if (cache[a][b] != -1) return cache[a][b];
int ret = 0;
rep(i, a + 1) rep(j, b + 1) ret += getv(i, j);
return ret;
}
void brute()
{
int polysize = 2;
}
const int mod = int(1e9 + 7);
signed main()
{
fast();
cin >> n;
int side = n * 2 + 1;
auto display = [&](vvi& grid)
{
int spacing = 3;
rep(i, side)
{
rep(j, side)
{
cout << grid[i][j];
rep(k, spacing - to_string(grid[i][j]).size()) cout << " ";
}
cout << "\n";
}
};
auto vis2 = [&]()
{
vvi grid(side, vi(side));
rep(i, side)
{
rep(j, side)
{
grid[i][j] = getv(i, j);
}
}
display(grid);
};
//vis1();
//display();
//vis2();
//display();
int q;
cin >> q;
rep(i, q)
{
int a, b, c, d;
cin >> a >> b >> c >> d;
swap(a, b);
//a = side - a - 1;
/*dread2(int, a, b);
a += n; b += n;
a = side - a-1;*/
cout << getv(-a, b) % mod << "\n";
}
return 0;
}
Compilation message
spiral.cpp: In function 'void brute()':
spiral.cpp:75:6: warning: unused variable 'polysize' [-Wunused-variable]
75 | int polysize = 2;
| ^~~~~~~~
spiral.cpp: In lambda function:
spiral.cpp:12:40: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'long long unsigned int' [-Wsign-compare]
12 | #define rep(i, high) for (int i = 0; i < high; i++)
......
98 | rep(k, spacing - to_string(grid[i][j]).size()) cout << " ";
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
spiral.cpp:98:5: note: in expansion of macro 'rep'
98 | rep(k, spacing - to_string(grid[i][j]).size()) cout << " ";
| ^~~
spiral.cpp: In function 'int main()':
spiral.cpp:106:7: warning: variable 'vis2' set but not used [-Wunused-but-set-variable]
106 | auto vis2 = [&]()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |