CSES - Datatähti 2021 alku - Results
Submission details
Task:Ratsun reitit
Sender:Otju
Submission time:2020-10-08 00:22:06 +0300
Language:Node.js
Status:READY
Result:58
Feedback
groupverdictscore
#1ACCEPTED27
#2ACCEPTED31
#30
Test results
testverdicttimegroup
#1ACCEPTED0.44 s1, 2, 3details
#2ACCEPTED0.44 s1, 2, 3details
#3ACCEPTED0.44 s1, 2, 3details
#4ACCEPTED0.44 s1, 2, 3details
#5ACCEPTED0.44 s1, 2, 3details
#6ACCEPTED0.44 s1, 2, 3details
#7ACCEPTED0.44 s1, 2, 3details
#8ACCEPTED0.45 s2, 3details
#9ACCEPTED0.53 s2, 3details
#10ACCEPTED0.54 s2, 3details
#11ACCEPTED0.86 s3details
#12--3details
#13--3details

Code

const { format } = require('path')
const readline = require('readline')

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
})

let n

rl.on('line', (line) => {
  n = parseInt(line)
  rl.close()
})

rl.on('close', () => {
  //console.time('ratsu')
  let tiles = []
  for (let y = 1; y <= n; y++) {
    for (let x = 1; x <= n; x++) {
      tiles.push({ y, x })
    }
  }
  tiles[0].number = "0"
  let currentTiles = [{ x: 1, y: 1 }]
  let i = 1
  while (true) {
    let possibleTiles = []
    let tilesWithOutNumbers = tiles.filter(pTile => !pTile.number)
    currentTiles.forEach(cTile => {
      const cx = cTile.x
      const cy = cTile.y

      tilesWithOutNumbers.forEach(pTile => {
        if (((pTile.x === cx - 2 || pTile.x === cx + 2) && (pTile.y === cy - 1 || pTile.y === cy + 1)) || ((pTile.x === cx - 1 || pTile.x === cx + 1) && (pTile.y === cy - 2 || pTile.y === cy + 2))) {
          pTile.number = i
          if (!possibleTiles.find(tile => tile.x === pTile.x && tile.y === pTile.y)) {
            possibleTiles.push(pTile)
          }
        }
      })
    })
    currentTiles = possibleTiles
    i++
    if (tilesWithOutNumbers.length === 0) {
      break
    }
  }
  let printOut = ""
  tiles.forEach(tile => {
    printOut = printOut.concat(`${tile.number} `)
    if (tile.x === n) {
      console.log(printOut)
      printOut = ""
    }
  })
 // console.timeEnd('ratsu')
})








Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
4

correct output
0 3 2 5 
3 4 1 2 
2 1 4 3 
5 2 3 2 

user output
0 3 2 5 
3 4 1 2 
2 1 4 3 
5 2 3 2 

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
5

correct output
0 3 2 3 2 
3 4 1 2 3 
2 1 4 3 2 
3 2 3 2 3 
2 3 2 3 4 

user output
0 3 2 3 2 
3 4 1 2 3 
2 1 4 3 2 
3 2 3 2 3 
2 3 2 3 4 

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
6

correct output
0 3 2 3 2 3 
3 4 1 2 3 4 
2 1 4 3 2 3 
3 2 3 2 3 4 
2 3 2 3 4 3 
...

user output
0 3 2 3 2 3 
3 4 1 2 3 4 
2 1 4 3 2 3 
3 2 3 2 3 4 
2 3 2 3 4 3 
...

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

input
7

correct output
0 3 2 3 2 3 4 
3 4 1 2 3 4 3 
2 1 4 3 2 3 4 
3 2 3 2 3 4 3 
2 3 2 3 4 3 4 
...

user output
0 3 2 3 2 3 4 
3 4 1 2 3 4 3 
2 1 4 3 2 3 4 
3 2 3 2 3 4 3 
2 3 2 3 4 3 4 
...

Test 5

Group: 1, 2, 3

Verdict: ACCEPTED

input
8

correct output
0 3 2 3 2 3 4 5 
3 4 1 2 3 4 3 4 
2 1 4 3 2 3 4 5 
3 2 3 2 3 4 3 4 
2 3 2 3 4 3 4 5 
...

user output
0 3 2 3 2 3 4 5 
3 4 1 2 3 4 3 4 
2 1 4 3 2 3 4 5 
3 2 3 2 3 4 3 4 
2 3 2 3 4 3 4 5 
...

Test 6

Group: 1, 2, 3

Verdict: ACCEPTED

input
9

correct output
0 3 2 3 2 3 4 5 4 
3 4 1 2 3 4 3 4 5 
2 1 4 3 2 3 4 5 4 
3 2 3 2 3 4 3 4 5 
2 3 2 3 4 3 4 5 4 
...

user output
0 3 2 3 2 3 4 5 4 
3 4 1 2 3 4 3 4 5 
2 1 4 3 2 3 4 5 4 
3 2 3 2 3 4 3 4 5 
2 3 2 3 4 3 4 5 4 
...

Test 7

Group: 1, 2, 3

Verdict: ACCEPTED

input
10

correct output
0 3 2 3 2 3 4 5 4 5 
3 4 1 2 3 4 3 4 5 6 
2 1 4 3 2 3 4 5 4 5 
3 2 3 2 3 4 3 4 5 6 
2 3 2 3 4 3 4 5 4 5 
...

user output
0 3 2 3 2 3 4 5 4 5 
3 4 1 2 3 4 3 4 5 6 
2 1 4 3 2 3 4 5 4 5 
3 2 3 2 3 4 3 4 5 6 
2 3 2 3 4 3 4 5 4 5 
...

Test 8

Group: 2, 3

Verdict: ACCEPTED

input
25

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

Test 9

Group: 2, 3

Verdict: ACCEPTED

input
49

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

Test 10

Group: 2, 3

Verdict: ACCEPTED

input
50

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

Test 11

Group: 3

Verdict: ACCEPTED

input
75

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

Test 12

Group: 3

Verdict:

input
99

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
(empty)

Test 13

Group: 3

Verdict:

input
100

correct output
0 3 2 3 2 3 4 5 4 5 6 7 6 7 8 ...

user output
(empty)