CSES - Datatähti 2025 alku - Results
Submission details
Task:Robotti
Sender:Username*
Submission time:2024-10-28 12:26:15 +0200
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:13:21: error: 'numeric_limits' is not a member of 'std'
   13 |     cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
      |                     ^~~~~~~~~~~~~~
input/code.cpp:13:51: error: expected primary-expression before '>' token
   13 |     cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
      |                                                   ^
input/code.cpp:13:57: error: no matching function for call to 'max()'
   13 |     cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
      |                                                    ~~~~~^~
In file included from /usr/include/c++/11/vector:60,
                 from input/code.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:254:5: note:   templa...

Code

#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
string line;
getline(cin, line);
size_t robot = line.find('R');
//cout << line << "\n";
//cout << robot << "\n";
vector<int> offsets;
int pos = 0;
int robpos = 0;
for (char room : line) {
if (room == '*') {
offsets.push_back(pos - robot);
}
else if (room == 'R') {
//offsets.push_back(0);
robpos = offsets.size()-1;
}
pos++;
}
/*cout << 1 << 2 << "\n";
return 0;*/
int totalscore = 0;
int steps = 0;
int roboff = 0;
while (offsets.size() > 0) {
/*cout << "\n";
for (int off : offsets) {
cout << off << " ";
}
cout << "\nstep:";*/
int left = offsets[robpos] - roboff;
int right = offsets[robpos+1] - roboff;
if (abs(left) > abs(right)) {
//cout << " right " << left << " " << right;
offsets.erase(offsets.begin()+robpos+1);
roboff += right;
steps += abs(right);
totalscore++;
}
else if (abs(right) > abs(left)){
//cout << " left " << left << " " << right;
offsets.erase(offsets.begin()+robpos);
robpos -= 1;
roboff += left;
steps += abs(left);
totalscore++;
}
else {
//cout << "same" << "\n";
break;
}
}
cout << steps << " " << totalscore << "\n";
return 0;
}