CSES - Datatähti 2025 alku - Results
Submission details
Task:Robotti
Sender:fatihmerickoc
Submission time:2024-10-28 14:45:51 +0200
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'std::pair<int, int> solve(std::string&)':
input/code.cpp:20:5: error: 'vector' was not declared in this scope
   20 |     vector<int> left_paralar, right_paralar;
      |     ^~~~~~
input/code.cpp:11:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
   10 | #include <algorithm>
  +++ |+#include <vector>
   11 | using namespace std;
input/code.cpp:20:12: error: expected primary-expression before 'int'
   20 |     vector<int> left_paralar, right_paralar;
      |            ^~~
input/code.cpp:24:17: error: 'left_paralar' was not declared in this scope
   24 |                 left_paralar.push_back(i);
      |                 ^~~~~~~~~~~~
input/code.cpp:26:17: error: 'right_paralar' was not declared in this scope
   26 |                 right_paralar.push_back(i);
      |                 ^~~~~~~~~~~~~
input/code.cpp:32:13: error: 'left_paralar' was not declared in this scope
   32 |     reverse(left_paralar.begin(),...

Code

//
// main.cpp
// mainCode
//
// Created by Fatih Meric Koc on 28.10.2024.
//
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
pair<int, int> solve(string& s) {
int n = s.length();
int robot_pozisyon = s.find('R');
int adimlar = 0;
int paralar = 0;
// Store coin positions in vectors (left and right of robot)
vector<int> left_paralar, right_paralar;
for (int i = 0; i < n; i++) {
if (s[i] == '*') {
if (i < robot_pozisyon) {
left_paralar.push_back(i);
} else {
right_paralar.push_back(i);
}
}
}
// Reverse left_paralar to process from closest to farthest
reverse(left_paralar.begin(), left_paralar.end());
// Indices for tracking current closest paralar
int left_idx = 0;
int right_idx = 0;
while (true) {
// Get distances to closest paralar on both sides
int left_dist = (left_idx < left_paralar.size()) ?
robot_pozisyon - left_paralar[left_idx] : n;
int right_dist = (right_idx < right_paralar.size()) ?
right_paralar[right_idx] - robot_pozisyon : n;
// No more paralar
if (left_dist == n && right_dist == n) {
break;
}
// Equal distance paralar - ambiguous case
if (left_dist == right_dist) {
break;
}
// Move to closest coin
if (left_dist < right_dist) {
adimlar += left_dist;
robot_pozisyon = left_paralar[left_idx];
left_idx++;
} else {
adimlar += right_dist;
robot_pozisyon = right_paralar[right_idx];
right_idx++;
}
paralar++;
}
return {adimlar, paralar};
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
string s;
cin >> n >> s;
pair<int, int> result = solve(s);
cout << result.first << " " << result.second << "\n";
return 0;
}