CSES - Datatähti 2022 alku - Results
Submission details
Task:Spiraali
Sender:ToukoP
Submission time:2021-10-04 23:11:49 +0300
Language:Node.js
Status:READY
Result:35
Feedback
groupverdictscore
#1ACCEPTED15
#2ACCEPTED20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.44 s1details
#2ACCEPTED0.46 s2details
#30.46 s3details

Code

var readline = require('readline');
var r = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});

function min(arr) {
    return arr.reduce((min, current) => min < current ? min : current);
}

function solve(n, x, y) {
    
    const layer = (x, y) => min([ x, n - x - 1, y, n - y - 1 ]);
    const sideLength = (l) => n - l * 2;

    const l = layer(x, y);
    
    let s = sideLength(l);
    let outside = n*n - s*s;
    s--;

    let debug = 0;

    let result = -2;
    if (x == l && y >= l && y < l + s) {
        result = outside +(y - l) +1;
        debug = 1;
    } else if (y == l) {
        result = outside -(x - l) +4*s +1;
        debug = 4;
    } else if (n - x - 1 == l) {
        result = outside -(y - l) +3*s +1;
        debug = 3;
    } else if (n - y - 1 == l) {
        result = outside +(x - l) +1*s +1;
        debug = 2;
    }

    return result;
}

let n, t;
r.on('line', function (line) {
    if (!n) {
        let input = line.split(' ');
        n = parseInt(input[0]);
        t = parseInt(input[1]);
        return;
    }

    let [ y, x ] = line.split(' ').map(v => parseInt(v));
    
    console.log(solve(n, x - 1, y - 1).toString());
});

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:

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

correct output
571375684522141210
967321186816598569
762879105851175000
370065046779516790
936897883750373771
...

user output
571375684522141200
967321186816598700
762879105851175000
370065046779516800
93689788375037
...
Truncated