CSES - Datatähti 2025 alku - Results
Submission details
Task:Robotti
Sender:qhuge
Submission time:2024-11-01 14:07:57 +0200
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:33:5: error: 'ios_base' has not been declared
   33 |     ios_base::sync_with_stdio(false);
      |     ^~~~~~~~
input/code.cpp:34:5: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   34 |     cin.tie(NULL);
      |     ^~~
      |     std::cin
In file included from input/code.cpp:1:
/usr/include/c++/11/iostream:60:18: note: 'std::cin' declared here
   60 |   extern istream cin;           /// Linked to standard input
      |                  ^~~
input/code.cpp:38:26: error: expected primary-expression before ')' token
   38 |     while(cin.getline(n))){
      |                          ^
input/code.cpp:42:28: error: 'map' was not declared in this scope
   42 |     std::getline(std::cin, map);
      |                            ^~~

Code

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
 
unsigned int robottiIndeksi;
 
long int etsi(std::vector<long int> kolikotX, int robottiX){
 
    if (kolikotX.size() <= 1){
        return 0;
    } else if (robottiIndeksi == 0){
        return kolikotX[1] - robottiX;
    } else if (robottiIndeksi == (kolikotX.size() - 1)){
        robottiIndeksi--;
        return kolikotX[kolikotX.size() - 2] - robottiX;
    }
 
    long int oik = abs(kolikotX[robottiIndeksi + 1] - robottiX);
    long int vas = abs(kolikotX[robottiIndeksi - 1] - robottiX);
 
    if (oik < vas) {
        return oik;
    } else if (vas < oik) {
        robottiIndeksi--;
        return -vas;
    } else {
        return 0;
    }
}
 
int main() { 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    long int n;
    std::cin >> n;
    std::vector<long int> kolikotX;
    while(cin.getline(n))){
        
    }

    std::getline(std::cin, map);
    std::cin >> map;
    
    
    long int robottiX = 0;
    /*for (unsigned int i = 0; i < map.size(); i++) {
        if (map[i] == '*'){
            kolikotX.push_back(i);
            continue;
        } else if (map[i] == 'R'){
            robottiX = i;
            kolikotX.push_back(-1);
            robottiIndeksi = kolikotX.size() - 1;
        }
    }*/
 
    long int askelia = 0;
    long int kolikoita = 0;
    while (true){
        long int et = etsi(kolikotX, robottiX);
        if (et == 0){
            break;
        }
        askelia = askelia + abs(et);
        robottiX = robottiX + et;
        kolikoita++;
        kolikotX.erase(remove(kolikotX.begin(), kolikotX.end(), robottiX), kolikotX.end());
        if (kolikotX.size() == 0) {
            break;
        }
    }
    std::cout << askelia << " " << kolikoita << "\n";
    return 0;
}