CSES - Datatähti 2022 alku - Results
Submission details
Task:Spiraali
Sender:kpop
Submission time:2021-10-06 08:18:36 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:20:9: error: expected ';' before 'vie'
         vie = cur;
         ^~~
input/code.cpp:60:34: error: 'mins' was not declared in this scope
             cout << result+(n-x)-mins;
                                  ^~~~
input/code.cpp:60:34: note: suggested alternative: 'main'
             cout << result+(n-x)-mins;
                                  ^~~~
                                  main

Code

#include <bits/stdc++.h>

using namespace std;

vector<int> vi;
int n, t;
int vie = 0;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> t;

    vi.push_back(0);

    for (int i = 0; i < floor(n/2); ++i) {
        int cur = ((i*(-2)+n)*4)-4;
        vi.push_back(vie+cur)
        vie = cur;
    }

    for (int i = 0; i < t; ++i) {
        int x, y;
        cin >> y >> x;

        int up = y-1;
        int bottom = n-y;
        int left = x-1;
        int right = n-x;

        int closest = min(up, min(bottom, min(left, right)));
        int nth = closest+1;

        int result = vi[closest];
        int side = n-(2*closest);

        if (closest == left) {
            cout << result+y-nth+1;
            continue;
        }

        result += side;

        if (closest == bottom) {
            cout << result+(x-nth);
            continue;
        }

        result += side-1;

        if (closest == right) {
            cout << result+n+y-closest;
            continue;
        }

        result += side-1;

        if (closest == up) {
            cout << result+(n-x)-mins;
        }
    }
}