CSES - Datatähti 2025 alku - Results
Submission details
Task:Robotti
Sender:osmukka
Submission time:2024-11-04 18:04:02 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:18:12: error: 'coin_rooms' was not declared in this scope
   18 |         if(coin_rooms[i] == 'R')
      |            ^~~~~~~~~~

Code

#include <iostream>
#include <vector>
#include <string>

int main()
{
    int amount = 0;
    char rooms[300000];
    int robot_index = 0;
    int steps = 0;
    int coins = 0;

    std::cin >> amount;
    std::cin >> rooms;

    for(int i = 0; i < amount; i++)
    {
        if(coin_rooms[i] == 'R')
        {
            robot_index = i;
        }
    }

    int l_coin;
    int r_coin;
    int d_left;
    int d_right;
    while(1)
    {
        l_coin = robot_index-1;
        r_coin = robot_index+1;

        while(rooms[l_coin] != '*' and l_coin >= 0)
        {
            l_coin--;
        }
        while(rooms[r_coin] != '*' and r_coin <= amount)
        {
            r_coin++;
        }
        l_coin = l_coin >= 0 ? l_coin : 9999999;
        r_coin = r_coin <= amount ? r_coin : -9999999;
        d_left = robot_index - l_coin;
        d_right = r_coin - robot_index;



        if(d_left < d_right)
        {
            steps += d_left;
            rooms[robot_index] = '.';
            robot_index--;
            rooms[robot_index] = 'R';
            coins++;
        }
        else if(d_right < d_left)
        {
            steps += d_right;
            rooms[robot_index] = '.';
            robot_index++;
            rooms[robot_index] = 'R';
            coins++;
        }
        else if(d_left == d_right)
        {
            break;
        }
    }

    std::cout << steps << " " << coins << "\n";
    return 0;
}