Task: | Ruudukko |
Sender: | TrixterTheTux |
Submission time: | 2019-10-03 12:59:17 +0300 |
Language: | Node.js |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 100 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.42 s | details |
#2 | ACCEPTED | 0.42 s | details |
#3 | ACCEPTED | 0.42 s | details |
#4 | ACCEPTED | 0.44 s | details |
#5 | ACCEPTED | 0.52 s | details |
#6 | ACCEPTED | 0.52 s | details |
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 |
---|
1 |
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 |