CSES - Datatähti 2022 alku - Results
Submission details
Task:Spiraali
Sender:Mahtimursu
Submission time:2021-10-04 00:36:10 +0300
Language:C++17
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1details
#20.01 s2details
#3--3details

Code

#include <bits/stdc++.h>

typedef long long ll;

#define M 1000000007
#define N (1 << 18)

using namespace std;

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 = 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;
            }
        } 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;
        }

        cout << ans << "\n";
    }   

    return 0;
}

Test details

Test 1

Group: 1

Verdict:

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
...

Test 2

Group: 2

Verdict:

input
1000 1000
371 263
915 322
946 880
53 738
...

correct output
773533
312166
206053
200080
593922
...

user output
773533
312167
206054
200080
593923
...

Test 3

Group: 3

Verdict:

input
1000000000 1000
177757853 827347032
409613589 419171337
739269360 256524697
328695530 896842209
...

correct output
571375684522141210
967321186816598569
762879105851175000
370065046779516790
936897883750373771
...

user output
(empty)