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

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:59:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         int right = (robpos + 1 < offsets.size()) ? (offsets[robpos + 1] - roboff) : INT_MAX;
      |                      ~~~~~~~~~~~^~~~~~~~~~~~~~~~
input/code.cpp:59:86: error: 'INT_MAX' was not declared in this scope
   59 |         int right = (robpos + 1 < offsets.size()) ? (offsets[robpos + 1] - roboff) : INT_MAX;
      |                                                                                      ^~~~~~~
input/code.cpp:7:1: note: 'INT_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
    6 | #include <limits>
  +++ |+#include <climits>
    7 |

Code

#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <string>
#include <limits>
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++;
}
int totalscore = 0;
int steps = 0;
int roboff = 0;
while (offsets.size() > 0) {
/*cout << "\n";
for (int off : offsets) {
cout << off << " ";
}
cout << "\nstep:";*/
/*if (offsets.size() == 1) {
int left = offsets[robpos] - roboff;
offsets.erase(offsets.begin() + robpos);
robpos -= 1;
roboff += left;
steps += abs(left);
totalscore++;
break;
}*/
int left = offsets[robpos] - roboff;
int right = (robpos + 1 < offsets.size()) ? (offsets[robpos + 1] - roboff) : INT_MAX;
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;
}