CSES - Datatähti 2025 alku - Results
Submission details
Task:Robotti
Sender:osmukka
Submission time:2024-11-04 18:01:46 +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')
      |            ^~~~~~~~~~
input/code.cpp:41:32: error: 'lcoin' was not declared in this scope; did you mean 'l_coin'?
   41 |         l_coin = l_coin >= 0 ? lcoin : 9999999;
      |                                ^~~~~
      |                                l_coin
input/code.cpp:51:19: error: request for member 'erase' in 'rooms', which is of non-class type 'char [200000]'
   51 |             rooms.erase(coin_rooms.begin()+robot_index);
      |                   ^~~~~
input/code.cpp:51:25: error: 'coin_rooms' was not declared in this scope
   51 |             rooms.erase(coin_rooms.begin()+robot_index);
      |                         ^~~~~~~~~~
input/code.cpp:58:19: error: request for member 'erase' in 'rooms', which is of non-class type 'char [200000]'
   58 |             rooms.erase(coin_rooms.begin()+robot_index);
      |...

Code

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

int main()
{
    int amount = 0;
    char rooms[200000];
    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 ? lcoin : 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.erase(coin_rooms.begin()+robot_index);
            robot_index--;
            coins++;
        }
        else if(d_right < d_left)
        {
            steps += d_right;
            rooms.erase(coin_rooms.begin()+robot_index);
            coins++;
        }
        else if(d_left == d_right)
        {
            break;
        }
    }

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