CSES - Datatähti 2025 alku - Results
Submission details
Task:Robotti
Sender:yo_chico1
Submission time:2024-10-29 20:49:06 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:18:30: error: too many arguments to function 'int findlCoin()'
   18 |         int lCoin = findlCoin(mapPic, myPos);
      |                     ~~~~~~~~~^~~~~~~~~~~~~~~
input/code.cpp:6:5: note: declared here
    6 | int findlCoin();
      |     ^~~~~~~~~
input/code.cpp:19:30: error: too many arguments to function 'int findrCoin()'
   19 |         int rCoin = findrCoin(mapPic, myPos, mapSize);
      |                     ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
input/code.cpp:5:5: note: declared here
    5 | int findrCoin();
      |     ^~~~~~~~~

Code

#include <iostream>
#include <string>
#include <cmath>

int findrCoin();
int findlCoin();

int main() {
    int mapSize, s_counter = 0, allCollected = 0;
    std::cin >> mapSize;

    std::string mapPic;
    std::cin >> mapPic;

    int myPos = mapPic.find('R');

    while (true) {
        int lCoin = findlCoin(mapPic, myPos);
        int rCoin = findrCoin(mapPic, myPos, mapSize);

        
        if (lCoin == -1 && rCoin == -1) break;

        
        if (lCoin == -1 || (rCoin != -1 && std::abs(rCoin - myPos) < std::abs(myPos - lCoin))) {
            s_counter += std::abs(rCoin - myPos);
            myPos = rCoin;
            allCollected++;
            mapPic[myPos] = '.';
        } else {
            s_counter += std::abs(myPos - lCoin);
            myPos = lCoin;
            allCollected++;
            mapPic[myPos] = '.';
        }
    }

    std::cout << s_counter << ' ' << allCollected << std::endl;
    return 0;
}


int findlCoin(std::string& mapPic, int start) {
    for (int i = start - 1; i >= 0; --i) {
        if (mapPic[i] == '*') return i;
    }
    return -1;
}

int findrCoin(std::string& mapPic, int start, int mapSize) {
    for (int i = start + 1; i < mapSize; ++i) {
        if (mapPic[i] == '*') return i;
    }
    return -1;
}