CSES - Datatähti 2022 alku - Results
Submission details
Task:Spiraali
Sender:EeliH
Submission time:2021-10-04 20:14:46 +0300
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1details
#20.01 s2details
#30.01 s3details

Code

#include <cmath>
#include <iostream>

using namespace std;

int64_t get_layer(int64_t x, int64_t y) {
    return max(abs(x), abs(y));
}

int64_t get_offset(int64_t x, int64_t y) {
    int64_t layer = get_layer(x, y);
    int64_t offset = 4 * layer * layer - 4 * layer + 1;
    return offset;
}

int64_t get_strip_i(int64_t x, int64_t y) {
    int64_t layer = get_layer(x, y);
    int64_t width = 2 * layer + 1;
    if(x == layer) {
        return (3 * width - 3) - y + layer - 1;
    } else if(y == -layer) {
        return layer - x - 1;
    } else if(x == -layer) {
        return (width - 1) + y + 1;
    } else if(y == layer) {
        return (2 * width - 2) + x + layer - 1;
    }
    return 1234;
}

int main()
{
    int64_t n, t;
    cin >> n >> t;
    //cout << get_offset(x, y) + get_strip_i(x, y) << endl;
    //cout << get_offset(x, y) << endl;
    //cout << get_strip_i(x, y) << endl;
    
    for(int64_t i = 0; i < t; i++) {
        int64_t x, y;
        cin >> y >> x;

        // Koordinaatit alkamaan (0,0)
        x--;
        y--;
    
        int64_t nx, ny;
        nx = (int64_t) (n / 2);
        ny = (int64_t) ((n - 1) / 2);
    
        x = x - nx;
        y = ny - y;

        int64_t arvo = n * n - (get_offset(x, y) + get_strip_i(x, y));
        //cout << "A " << get_strip_i(x, y) << endl;
        //cout << "B " << get_offset(x, y) << endl;
        cout << arvo << endl;
        //cout << x << " " << y << endl;
    }

    //cout << "AAAA" << endl;

    //cout << get_strip_i(-2, 2) << endl;
    //cout << get_strip_i(-1, 2) << endl;
    //cout << get_strip_i(0, 2) << endl;
    //cout << get_strip_i(1, 2) << endl;
    //cout << get_strip_i(2, 2) << endl;
    //cout << get_strip_i(2, 1) << endl;
    //cout << get_strip_i(2, 0) << endl;
    //cout << get_strip_i(2, -1) << endl;
    //cout << get_strip_i(2, -2) << endl;
    //cout << get_strip_i(1, -2) << endl;
    //cout << get_strip_i(0, -2) << endl;
    //cout << get_strip_i(-1, -2) << endl;
    //cout << get_strip_i(-2, -2) << endl;
    //cout << get_strip_i(-2, -1) << endl;
    //cout << get_strip_i(-2, 0) << endl;
    //cout << get_strip_i(-2, 1) << endl;
}

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
4
38
35
34
33
...
Truncated

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
773769
312166
206053
200080
593922
...
Truncated

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
571375684522141210
967321186816598569
762879106094650302
370065046779516790
93689788375037
...
Truncated