CSES - Datatähti 2025 alku - Results
Submission details
Task:Robotti
Sender:Jens-Mikael
Submission time:2024-11-09 13:40:09 +0200
Language:Node.js
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#1ACCEPTED0.11 s1, 2details
#2ACCEPTED0.11 s1, 2details
#3ACCEPTED0.11 s1, 2details
#4ACCEPTED0.11 s1, 2details
#5ACCEPTED0.12 s1, 2details
#60.15 s1, 2details
#70.15 s1, 2details
#8ACCEPTED0.11 s1, 2details
#9ACCEPTED0.11 s1, 2details
#10ACCEPTED0.15 s1, 2details
#110.15 s1, 2details
#12ACCEPTED0.41 s2details
#13--2details
#14--2details
#15--2details
#16--2details
#17ACCEPTED0.12 s2details
#18--2details
#19--2details
#20ACCEPTED0.12 s2details
#21ACCEPTED0.18 s2details
#22--2details
#23--2details
#24--2details

Code

const readline = require("readline");

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

const main = (rooms, house) => {
  //find the closest coin

  let newHouse = house;
  let coins = 0;
  let steps = 0;

  while (newHouse.includes("*")) {

    const robotIndex = newHouse.indexOf("R");

    const rightSide = newHouse.slice(robotIndex);
    const right = rightSide.indexOf("*");
    //console.log("🚀 ~ main ~ right:", right);
    const leftSide = newHouse.slice(0, robotIndex);
    const left =
      leftSide.lastIndexOf("*") === -1
        ? -1
        : leftSide.length - leftSide.lastIndexOf("*"); //split("").reverse().join("").indexOf("*");
    //console.log("🚀 ~ main ~ left:", left);

    //if (right !== -1 && left !== -1) {
    //if right side is closer
    if (right < left || left === -1) {
      //console.log(right);

      coins++;
      steps += right;

      const houseArr = newHouse.split("");

      houseArr.splice(robotIndex, 1, "O");
      houseArr.splice(robotIndex + right, 1, "R");
      newHouse = houseArr.join("");
      //if (right === 18) console.log(houseArr.join(""));

      //if left side is closer
    } else if (left < right || right === -1) {
      coins++;
      steps += left;
      const houseArr = newHouse.split("");
      houseArr.splice(robotIndex, 1, "O");
      houseArr.splice(robotIndex - left, 1, "R");
      newHouse = houseArr.join("");
    } else {
      //they're equally close
      break;
    }
  }
  //**.*......*.R*...*...
  return `${steps} ${coins}`;
};

let inputs = [];

r.on("line", (line) => {
  inputs.push(line);
  if (inputs.length === 2) {
    console.log(main(inputs[0], inputs[1]));

    r.close();
  }
});

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
1
R

correct output
0 0

user output
0 0

Test 2

Group: 1, 2

Verdict: ACCEPTED

input
10
...R......

correct output
0 0

user output
0 0

Test 3

Group: 1, 2

Verdict: ACCEPTED

input
10
**.R...***

correct output
12 5

user output
12 5

Test 4

Group: 1, 2

Verdict: ACCEPTED

input
10
***R******

correct output
0 0

user output
0 0

Test 5

Group: 1, 2

Verdict: ACCEPTED

input
1000
R................................

correct output
947 9

user output
947 9

Test 6

Group: 1, 2

Verdict:

input
1000
.................................

correct output
886 9

user output
-886 886

Test 7

Group: 1, 2

Verdict:

input
1000
.....*..*....**..**..*......*....

correct output
1287 400

user output
-691 1110

Test 8

Group: 1, 2

Verdict: ACCEPTED

input
1000
************.*****************...

correct output
0 0

user output
0 0

Test 9

Group: 1, 2

Verdict: ACCEPTED

input
1000
******************************...

correct output
0 0

user output
0 0

Test 10

Group: 1, 2

Verdict: ACCEPTED

input
1000
R*****************************...

correct output
999 999

user output
999 999

Test 11

Group: 1, 2

Verdict:

input
1000
******************************...

correct output
999 999

user output
-999 999

Test 12

Group: 2

Verdict: ACCEPTED

input
10000
.......**........*...........*...

correct output
10971 999

user output
10971 999

Test 13

Group: 2

Verdict:

input
10000
*..*....*......*.....*..*........

correct output
9999 999

user output
(empty)

Test 14

Group: 2

Verdict:

input
10000
*.*.*...**.*...*....**.**.**.....

correct output
18766 5000

user output
(empty)

Test 15

Group: 2

Verdict:

input
10000
R*****************************...

correct output
9999 9999

user output
(empty)

Test 16

Group: 2

Verdict:

input
10000
******************************...

correct output
9999 9999

user output
(empty)

Test 17

Group: 2

Verdict: ACCEPTED

input
200000
.................................

correct output
0 0

user output
0 0

Test 18

Group: 2

Verdict:

input
200000
.................................

correct output
299934 10000

user output
(empty)

Test 19

Group: 2

Verdict:

input
200000
**.***....**..**.....***.*..*....

correct output
299998 100000

user output
(empty)

Test 20

Group: 2

Verdict: ACCEPTED

input
200000
******************************...

correct output
0 0

user output
0 0

Test 21

Group: 2

Verdict: ACCEPTED

input
200000
R................................

correct output
133765 3

user output
133765 3

Test 22

Group: 2

Verdict:

input
200000
R................................

correct output
199982 5000

user output
(empty)

Test 23

Group: 2

Verdict:

input
200000
R*****************************...

correct output
199999 199999

user output
(empty)

Test 24

Group: 2

Verdict:

input
200000
******************************...

correct output
199999 199999

user output
(empty)