Submission #987255

#TimeUsernameProblemLanguageResultExecution timeMemory
987255andrei_iorgulescuSpiral (BOI16_spiral)C++17
31 / 100
1 ms432 KiB
#include <bits/stdc++.h> using namespace std; #define int __int128 using ll = long long; int modulo = 1e9 + 7; void testcase() { ll X1,Y1,X2,Y2; cin >> X1 >> Y1 >> X2 >> Y2; int x1 = X1,x2 = X2,y1 = Y1,y2 = Y2; if (x1 == 1 and y1 == 1) { int x = x2,y = y2,d = min(x2,y2); int s = -d + 2 * d * d * (d + 1) * (d + 1) - 2 * d * (d + 1) * (2 * d + 1) + 3 * d * (d + 1) + 4 * d * (d + 1) * (2 * d + 1) / 6 - d * (d + 1); s %= modulo; if (x == y) cout << (ll)s << '\n'; else if (x > y) { int s2 = (x - y) * y * (y + 1) / 2 + y * x * (x + 1) / 2 - y * y * (y + 1) / 2 + y * (x - y) + 4 * y * x * (x + 1) * (2 * x + 1) / 6 - 4 * y * y * (y + 1) * (2 * y + 1) / 6 - 4 * y * x * (x + 1) / 2 + 4 * y * y * (y + 1) / 2; s += s2; s %= modulo; cout << (ll)s << '\n'; } else { int s2 = x * (y - x) + 4 * x * y * (y + 1) * (2 * y + 1) / 6 - 4 * x * x * (x + 1) * (2 * x + 1) / 6 + 2 * x * x * (x + 1) - 2 * x * y * (y + 1) + x * y * (y + 1) - x * x * (x + 1) - (y - x) * x * x + x * y * (y + 1) / 2 - x * x * (x + 1) / 2 + (y - x) * x * (x - 1) / 2; s += s2; s %= modulo; cout << (ll)s << '\n'; } } } signed main() { ll n,tc; cin >> n >> tc; while (tc--) testcase(); return 0; } /** cea mai de mate de a 5a problema **/ /** idee: hai sa luam subtaskul ala de x1 = y1 = 1 Daca ar fi un patrat d * d, formula (doamne ajuta sa fi dat bine) este: S = -d + 2 * d * d * (d + 1) * (d + 1) - 2 * d * (d + 1) * (2 * d + 1) + 3 * d * (d + 1) + 4 * d * (d + 1) * (2 * d + 1) / 6 - d * (d + 1) Daca X > Y, mai am un S2 = (x - y) * y * (y + 1) / 2 + y * x * (x + 1) / 2 - y * y * (y + 1) / 2 + y * (x - y) + 4 * y * x * (x + 1) * (2 * x + 1) / 6 - 4 * y * (y + 1) * (2 * y + 1) / 6 - 4 * y * x * (x + 1) / 2 + 4 * y * (y + 1) / 2 Daca X < Y, mai am un S2 = x * (y - x) + 4 * x * y * (y + 1) * (2 * y + 1) / 6 - 4 * x * x * (x + 1) * (2 * x + 1) / 6 + 4 * x * x * (x + 1) / 2 - 4 * x * y * (y + 1) / 2 + x * y * (y + 1) - x * x * (x + 1) - (y * x) * x * x + x * y * (y + 1) / 2 - x * x * (x + 1) / 2 + (y - x) * x * (x - 1) / 2 Care-i sansa sa nu fi gresit niciun calcul? Upd: 0 **/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...