Task: | Spiraali |
Sender: | Mahtimursu |
Submission time: | 2021-10-04 00:41:37 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 35 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 15 |
#2 | ACCEPTED | 20 |
#3 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1 | details |
#2 | ACCEPTED | 0.01 s | 2 | details |
#3 | TIME LIMIT EXCEEDED | -- | 3 | details |
Code
#include <bits/stdc++.h> typedef long long ll; #define M 1000000007 #define N (1 << 18) using namespace std; ll calculate(ll n, ll y, ll x) { ll ans = 0; ll outside = min(min(x - 1, n - x), min(y - 1, n - y)); ll size = n; for (int it = 0; it < outside; ++it) { ans += size * 4 - 4; size -= 2; } if (x == outside + 1) { // Going down ans += y - outside; } else if (x < n - outside) { // In the middle. // Left downwards ans += n - outside * 2; // Traveling above if (y <= n / 2) { // Lower part - left corner ans += n - outside * 2 - 1; // Right part - right down corner ans += n - outside * 2 - 1; // Going from left ans += n - x - outside; } else { // Traveling below ans += x - outside - 1; } } else { // Right going up // Left ans += n - outside * 2; // Lower part - left down corner ans += n - outside * 2 - 1; // up part ans += n - y - outside; } return ans; } int matrix[6][6] = { {1, 20, 19, 18, 17, 16} , {2, 21, 32, 31, 30, 15} , {3, 22, 33, 36, 29, 14} , {4, 23, 34, 35, 28, 13} , {5, 24, 25, 26, 27, 12} , {6, 7, 8, 9, 10, 11} }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); ll n, t; cin >> n >> t; for (int i = 0; i < t; ++i) { ll x, y; cin >> y >> x; ll ans = calculate(n, y, x); cout << ans << "\n"; } /*for (int x = 1; x <= n; ++x) { for (int y = 1; y <= n; ++y) { ll ans = calculate(n, y, x); ll cor = matrix[y - 1][x - 1]; if (ans != cor) { cout << "FAIL" << endl; cout << x << ", " << y << " COR " << cor << " GOT " << ans << endl; } } }*/ return 0; }
Test details
Test 1
Group: 1
Verdict: ACCEPTED
input |
---|
10 100 1 1 1 2 1 3 1 4 ... |
correct output |
---|
1 36 35 34 33 ... |
user output |
---|
1 36 35 34 33 ... Truncated |
Test 2
Group: 2
Verdict: ACCEPTED
input |
---|
1000 1000 371 263 915 322 946 880 53 738 ... |
correct output |
---|
773533 312166 206053 200080 593922 ... |
user output |
---|
773533 312166 206053 200080 593922 ... Truncated |
Test 3
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000000000 1000 177757853 827347032 409613589 419171337 739269360 256524697 328695530 896842209 ... |
correct output |
---|
571375684522141210 967321186816598569 762879105851175000 370065046779516790 936897883750373771 ... |
user output |
---|
(empty) |