CSES - Datatähti 2021 alku - Results
Submission details
Task:Ratsun reitit
Sender:Otju
Submission time:2020-10-08 10:32:41 +0300
Language:Node.js
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.44 s1, 2, 3details
#20.44 s1, 2, 3details
#30.44 s1, 2, 3details
#40.44 s1, 2, 3details
#50.44 s1, 2, 3details
#60.44 s1, 2, 3details
#70.44 s1, 2, 3details
#80.47 s2, 3details
#90.81 s2, 3details
#100.84 s2, 3details
#11--3details
#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 inputN

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

rl.on('close', () => {
  first = (n) => {
    //console.time('ratsu')
    let tiles = []
    let currentTiles = [{ x: 1, y: 1, number: "0" }]
    tiles.push(currentTiles[0])
    let i = 1
    while (true) {

      let newTiles = []
      currentTiles.forEach(cTile => {
        const cx = cTile.x
        const cy = cTile.y
        const arrayX = [-2, 2, -1, 1]
        arrayX.forEach(numberX => {
          let arrayY
          (numberX === -2 || numberX === 2)
            ? arrayY = [-1, 1]
            : arrayY = [-2, 2]
          arrayY.forEach(numberY => {
            x = cx + numberX
            y = cy + numberY
            if (x > 0 && x <= n && (y > 0 && y <= n)) {
              if (!tiles.find(item => item.x === x && item.y === y)) {
                const tile = { x, y, number: i }
                newTiles.push(tile)
                tiles.push(tile)
              }
            }
          })
        })
      })
      currentTiles = newTiles
      i++
      if (tiles.length === n * n) {
        break
      }
    }
    tiles = tiles.sort((a, b) => a.x - b.x)
    tiles = tiles.sort((a, b) => a.y - b.y)
    let printOut = ""
    tiles.forEach(tile => {
      printOut = printOut.concat(`${tile.number} `)
      if (tile.x === n && tile.y !== n) {
        printOut = printOut.concat("\n")
      }
    })
    return (printOut)
  }
  const second = (n) => {
    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 = []
      currentTiles.forEach(cTile => {
        const cx = cTile.x
        const cy = cTile.y
        tiles.forEach((pTile, ii) => {
          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))) {
            if (!pTile.number && pTile.number !== 0) {
              tiles[ii].number = i
              possibleTiles.push(pTile)
            }
          }
        })
      })
      currentTiles = possibleTiles
      i++
      if (tiles.filter(tile => tile.number).length + 1 === tiles.length) {
        break
      }
    }
    let printOut = ""
    tiles.forEach(tile => {
      printOut = printOut.concat(`${tile.number} `)
      if (tile.x === n && tile.y !== n) {
        printOut = printOut.concat("\n")
      }
    })
    return (printOut)
  }
  /*
  for(let i = 4; i<=100; i++){
    console.log(first(i)===second(i))
  }
  */
  console.log(first(inputN))
  //console.log(second(inputN))
})








Test details

Test 1

Group: 1, 2, 3

Verdict:

input
4

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

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

Test 2

Group: 1, 2, 3

Verdict:

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 2 
3 2 3 2 4 3 3 
1 4 1 2 3 2 
2 3 3 
3 2 3 2 4 2 3 

Test 3

Group: 1, 2, 3

Verdict:

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 3 2 3 2 4 3 4 
1 3 
4 2 2 3 1 3 3 3 2 2 4 

...

Test 4

Group: 1, 2, 3

Verdict:

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
2 0 3 3 3 2 4 
4 3 
1 3 4 2 3 4 
2 1 3 3 2 4 2 4 3 2 3 
3 3 3 2 2 4 
...

Test 5

Group: 1, 2, 3

Verdict:

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 2 5 
4 3 3 2 3 4 1 3 4 4 
3 2 3 4 4 2 2 1 3 5 
3 3 2 3 3 3 4 
2 4 3 4 2 5 
...

Test 6

Group: 1, 2, 3

Verdict:

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
3 5 3 3 4 4 
0 2 2 4 5 
1 3 3 4 2 4 3 4 2 1 4 4 
5 3 2 3 2 3 5 
3 3 3 4 4 2 3 4 
...

Test 7

Group: 1, 2, 3

Verdict:

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
2 5 
3 3 5 0 2 3 4 4 3 4 6 
1 2 3 4 4 3 5 5 
4 4 4 3 1 5 2 2 3 2 3 3 4 5 6 
3 4 2 3 5 4 2 2 4 3 3 3 4 5 
...

Test 8

Group: 2, 3

Verdict:

input
25

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

user output
0 12 
13 12 11 10 11 10 9 8 9 8 7 6 ...

Test 9

Group: 2, 3

Verdict:

input
49

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

user output
25 6 15 16 7 17 7 6 15 16 11 1...

Test 10

Group: 2, 3

Verdict:

input
50

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

user output
0 7 6 6 23 18 7 22 5 23 8 9 4 ...

Test 11

Group: 3

Verdict:

input
75

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

user output
(empty)

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)