Submission #349427

# Submission time Handle Problem Language Result Execution time Memory
349427 2021-01-17T15:25:05 Z sinamhdv Spiral (BOI16_spiral) C++11
27 / 100
1500 ms 512 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1000 * 1000 * 1000;
const ll LINF = (ll)INF * INF;

#ifdef DEBUG
#define dbg(x) cout << #x << " = " << (x) << endl << flush;
#define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; }
#else
#define dbg(x) ;
#define dbgr(s, f) ;
#endif
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define msub(a, b) ((mod + ((ll)(a) - (b)) % mod) % mod)
#define mdiv(a, b) ((ll)(a) * poww((b), mod - 2) % mod)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define endl '\n'

int n, q;

ll get(int x, int y)
{
	ll d = max(abs(x), abs(y)) + 1;
	ll ur = 4 * d * d - 10 * d + 7;
	ll off = 0;
	d--;
	if (y == d)
		off = d - x;
	else if (y == -d)
	{
		off = x + 5 * d;
	}
	else if (x == d)
	{
		off = y - d;
	}
	else if (x == -d)
	{
		off = 3 * d - y;
	}
	return ur + off;
}

int32_t main(void)
{
	fast_io;
	cin >> n >> q;

	while (q--)
	{
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		ll ans = 0;
		FOR(i, x1, x2 + 1)
		{
			FOR(j, y1, y2 + 1)
			{
				ans = (ans + get(i, j)) % mod;
			}
		}
		cout << ans << endl;
		dbg("");
	}
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 251 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 251 ms 492 KB Output is correct
2 Execution timed out 1555 ms 512 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1551 ms 364 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 251 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Execution timed out 1555 ms 512 KB Time limit exceeded