CSES - Datatähti 2023 alku - Results
Submission details
Task:Lehmät
Sender:Esinko
Submission time:2022-10-31 14:10:39 +0200
Language:Node.js
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED28
#2ACCEPTED72
Test results
testverdicttimegroup
#1ACCEPTED0.11 s1, 2details
#2ACCEPTED0.11 s1, 2details
#3ACCEPTED0.11 s1, 2details
#4ACCEPTED0.11 s1, 2details
#5ACCEPTED0.11 s1, 2details
#6ACCEPTED0.11 s2details
#7ACCEPTED0.11 s2details
#8ACCEPTED0.11 s2details
#9ACCEPTED0.12 s2details

Code

// Suorakulmion muotoinen aitaus
// Annetaan kartta
// Kuinka monta alueella

const { createInterface } = require("readline")
const interface = createInterface({
    input: process.stdin,
    terminal: false
})

let dimensions = {}
let data = []

interface.on("line", (line) => {
    if (Object.keys(dimensions).length === 0) {
        const givenDimensions = line.split(" ")
        dimensions.height = givenDimensions[0]
        dimensions.width = givenDimensions[1]
    } else if (data.length !== dimensions.height) data.push(line.split("").map((val) => val === "." ? 0 : val === "*" ? 2 : 1 ))
    if (data.length == dimensions.height) {
        // If the line includes more than 2 *, then we ignore it
        // If the line includes * at some point, we begin the fence
        // If the line includes a second * we end the fence
        // When within lines, calculate amount of true values
        // 2 = fence, 1 = cow, 0 = empty space
        const amountOfCowsWithinBounds = data
            .map((row) =>
                row.filter((val) => val === 2).length !== 2 ? 
                0 :
                row.slice(row.indexOf(2) + 1, row.indexOf(2, row.indexOf(2) + 1))
                    .filter((val) => val === 1)
                    .length
            )
            .flat(1)
            .reduce((a, b) => a + b)
        console.log(amountOfCowsWithinBounds)
        process.exit()
    }
})

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
3 3
***
*.*
***

correct output
0

user output
0

Test 2

Group: 1, 2

Verdict: ACCEPTED

input
3 3
***
*@*
***

correct output
1

user output
1

Test 3

Group: 1, 2

Verdict: ACCEPTED

input
5 10
...@......
..******..
@.*@@@@*.@
..******..
...

correct output
4

user output
4

Test 4

Group: 1, 2

Verdict: ACCEPTED

input
10 10
@@...@.@@@
..@@.@@..@
@.*******@
..*@....*.
...

correct output
11

user output
11

Test 5

Group: 1, 2

Verdict: ACCEPTED

input
10 10
**********
*@@@@@@@@*
*@@@@@@@@*
*@@@@@@@@*
...

correct output
64

user output
64

Test 6

Group: 2

Verdict: ACCEPTED

input
100 100
.........................@.......

correct output
60

user output
60

Test 7

Group: 2

Verdict: ACCEPTED

input
100 100
..@@..........@......@....@@.....

correct output
1507

user output
1507

Test 8

Group: 2

Verdict: ACCEPTED

input
100 100
.@..@@..@@.@..@..@..@@..@..@.....

correct output
3348

user output
3348

Test 9

Group: 2

Verdict: ACCEPTED

input
100 100
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...

correct output
7225

user output
7225