CSES - Datatähti 2020 alku - Results
Submission details
Task:Ruudukko
Sender:AtskaFin
Submission time:2019-09-30 20:03:02 +0300
Language:Node.js
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.43 sdetails
#2ACCEPTED0.43 sdetails
#3ACCEPTED0.43 sdetails
#4ACCEPTED0.44 sdetails
#5ACCEPTED0.55 sdetails
#6ACCEPTED0.55 sdetails

Code

const readLine = require('readline')

const read = readLine.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});

read.on('line', n => {   
    let grid = [[]]
    let row = []

    for(let i = 0; i < n; i++) grid[0][i] = i + 1

    for(let a = 1; a < n; a++) {
        row.push(grid.length + 1)
        for(let b = 1; b < n; b++) {
            let num = 0
            while(true) {
                num++
                let doesFit = true
                for(let c = 0; c < grid.length; c++) {
                    if(grid[c][row.length] == num) doesFit = false
                }
                if(!doesFit) continue
                if(!row.includes(num)) break
            }
            row.push(num)
        }
        grid.push(row)
        row = []
    }

    for(let i = 0; i < grid.length; i++) {
        console.log(grid[i].join(' '))
    }
})

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 ...
Truncated

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 ...
Truncated

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 ...
Truncated