CSES - Datatähti 2020 alku - Results
Submission details
Task:Ruudukko
Sender:TrixterTheTux
Submission time:2019-10-03 12:59:17 +0300
Language:Node.js
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.42 sdetails
#2ACCEPTED0.42 sdetails
#3ACCEPTED0.42 sdetails
#4ACCEPTED0.44 sdetails
#5ACCEPTED0.52 sdetails
#6ACCEPTED0.52 sdetails

Code

const stdin = process.openStdin();
stdin.addListener('data', input => {
    calculate(parseInt(input.toString().trim()));
});

function calculate(input) {
    const res = [];
    for(let y = 0; y < input; y++) {
        res[y] = [];

        for(let x = 0; x < input; x++) {
            if (y === 0) res[y].push(x + 1);
            else if(x === 0) res[y].push(y + 1);
            else {
                const reserved = [];

                // left row
                for(let l = 0; l < x; l++) {
                    const val = res[y][l];
                    reserved.push(val);
                }

                // top row
                for(let t = 0; t < y; t++) {
                    const val = res[t][x];
                    reserved.push(val);
                }

                for(let n = 1; n <= input ** 2; n++) {
                    if (!reserved.includes(n)) {
                        res[y].push(n);
                        break;
                    }
                }
            }
        }
    }

    console.log(res.map(a => a.join(' ')).join('\n'));
}

Test details

Test 1

Verdict: ACCEPTED

input
1

correct output

user output
1

Test 2

Verdict: ACCEPTED

input
2

correct output
1 2 
2 1 

user output
1 2
2 1

Test 3

Verdict: ACCEPTED

input
5

correct output
1 2 3 4 5 
2 1 4 3 6 
3 4 1 2 7 
4 3 2 1 8 
5 6 7 8 1 

user output
1 2 3 4 5
2 1 4 3 6
3 4 1 2 7
4 3 2 1 8
5 6 7 8 1

Test 4

Verdict: ACCEPTED

input
42

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 5

Verdict: ACCEPTED

input
99

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 6

Verdict: ACCEPTED

input
100

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...