CSES - Datatähti 2022 alku - Results
Submission details
Task:Spiraali
Sender:motsgar
Submission time:2021-10-04 02:21:45 +0300
Language:C++17
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1details
#20.01 s2details
#30.01 s3details

Code

#include <bits/stdc++.h>

using namespace std;

int n, t;

int start;

int get(int p)
{
    return n * n + p * ((-4 * (p - 1) * 2 - 4) / 2) - p;
}

int main(int argc, char **argv)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> t;

    int centerX = n / 2 + 1;
    int centerY = n / 2;
    if (n % 2 == 1)
    {
        centerY++;
    }

    for (int i = 0; i < t; i++)
    {
        int x, y;
        cin >> x >> y;
        int rengas = max(abs(centerX - x), abs(centerY - y));
        int arvo = get(rengas);
        if (n % 2 == 0)
        {
            if (y == centerY + rengas && x < centerX + rengas)
            {
                arvo += rengas;
                arvo += x - (centerX - rengas);
            }
            else if (x == centerX - rengas)
            {
                arvo += y - centerY;
            }
            else if (y == centerY - rengas)
            {
                arvo -= rengas;
                arvo -= x - (centerX - rengas);
            }
            else
            {
                arvo -= rengas + 2 * (rengas - 1);
                arvo -= y - (centerY - rengas);
            }
        }
        else
        {
            if (y == centerY - rengas && x > centerX - rengas)
            {
                arvo += rengas;
                arvo -= x - centerX - rengas;
            }
            else if (x == centerX + rengas)
            {
                arvo -= y - centerY;
            }
            else if (y == centerY + rengas)
            {
                arvo -= rengas;
                arvo += x - (centerX + rengas);
            }
            else
            {
                arvo -= rengas + 2 * (rengas - 1);
                arvo += y - (centerY + rengas);
            }
        }
        cout << arvo << "\n";
    }
}

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
2
3
4
5
...

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
775217
313354
206187
197870
594542
...

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
399311524
1643368629
2036373734
1163551112
368111459
...