CSES - Datatähti 2022 alku - Results
Submission details
Task:Spiraali
Sender:AnttiE
Submission time:2021-10-05 16:06:54 +0300
Language:Node.js
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.43 s1details
#20.43 s2details
#30.43 s3details

Code

const input = () => new Promise(r => process.stdin.once("data", d => r(d.toString().trim())));
(async () => {
    // -- START --

    const dist = (r1, c1, r2, c2) => Math.abs(r2 - r1) + Math.abs(c2 - c1);

    // ngl not proud of this one
    // + miksi koordinaatit alkaa 1,1 eikä 0,0...
    const solve = (size, r, c) => {
        const centers = [
            [size / 2, 1], // left
            [size, size / 2], // bottom
            [(size / 2) + 1, size], // right
            [1, (size / 2) + 1] // top
        ];
        for (const center in centers) {
            if (dist(...centers[center], r, c) <= (size / 2) - 1) {
                let ans;
                switch (center) {
                    case "0": {
                        ans = 0;
                        for (let i = 0; i < (c - 1); i++) {
                            ans += (size - 1 - (i * 2)) * 4;
                        }
                        ans += r - (c - 1);
                        break;
                    }
                    case "1": {
                        ans = size - 1;
                        for (let i = 0; i < (size - r); i++) {
                            ans += (size - 1 - (i * 2)) * 4 - 2;
                        }
                        ans += c - (size - r);
                        break;
                    }
                    case "2": {
                        ans = (size - 1) * 2;
                        for (let i = 0; i < (size - c); i++) {
                            ans += (size - 1 - (i * 2)) * 4 - 4;
                        }
                        ans += (size - r) - (size - c) + 1;
                        break;
                    }
                    case "3": {
                        ans = (size - 1) * 3;
                        for (let i = 0; i < (r - 1); i++) {
                            ans += (size - 1 - (i * 2)) * 4 - 7;
                        }
                        ans += (size - c) + 1;
                        break;
                    }
                }
                return ans ?? 0;
            }
        }
    };

    const [size, count] = (await input()).split(" ").map(Number);
    const tests = [];

    for (let i = 0; i < count; i++) tests.push((await input()).split(" ").map(Number));

    for (const test of tests) console.log(solve(size, test[0], test[1]).toString());

    // -- END --
    process.exit(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
(empty)

Error:
/box/input/code.js:53
                return ans ?? 0;
                            ^

SyntaxError: Unexpected token ?
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3

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
(empty)

Error:
/box/input/code.js:53
                return ans ?? 0;
                            ^

SyntaxError: Unexpected token ?
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3

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)

Error:
/box/input/code.js:53
                return ans ?? 0;
                            ^

SyntaxError: Unexpected token ?
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3