| Task: | Robotti |
| Sender: | Interaalimato |
| Submission time: | 2024-10-28 12:49:13 +0200 |
| Language: | C++ (C++20) |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:32:5: error: 'queue' was not declared in this scope
32 | queue<int> rightPos;
| ^~~~~
input/code.cpp:4:1: note: 'std::queue' is defined in header '<queue>'; did you forget to '#include <queue>'?
3 | #include <stack>
+++ |+#include <queue>
4 |
input/code.cpp:32:11: error: expected primary-expression before 'int'
32 | queue<int> rightPos;
| ^~~
input/code.cpp:43:17: error: 'rightPos' was not declared in this scope
43 | rightPos.push(i);
| ^~~~~~~~
input/code.cpp:51:33: error: 'rightPos' was not declared in this scope
51 | while (!leftPos.empty() || !rightPos.empty())
| ^~~~~~~~Code
#include <iostream>
#include <cmath>
#include <stack>
using namespace std;
// vector<tuple<string, int, int>> testcases = {
// make_tuple("**.*......*.R*...*..", 4, 2),
// make_tuple("***.R****", 12, 7),
// make_tuple("****R.***", 12, 7),
// make_tuple("R**********", 10, 10),
// make_tuple("*************************************R****", 0, 0),
// make_tuple("*.*.*R..*", 13, 4),
// make_tuple("*.*..R***", 11, 5),
// make_tuple("**...*R..*", 1, 1),
// make_tuple("*...R**.....*", 2, 2),
// };
int main()
{
// for (const auto &t : testcases)
// {
// string huoneet = get<0>(t);
int n;
string huoneet;
cin >> n >> huoneet;
// int n = huoneet.length();
int kolikot = 0;
int askeleet = 0;
int pos = -1;
stack<int> leftPos;
queue<int> rightPos;
for (int i = 0; i < n; i++)
{
if (huoneet.at(i) == 'R')
{
pos = i;
}
else if (huoneet.at(i) == '*')
{
if (pos != -1)
{
rightPos.push(i);
}
else
{
leftPos.push(i);
}
}
}
while (!leftPos.empty() || !rightPos.empty())
{
if (!leftPos.empty() && !rightPos.empty() && pos - leftPos.top() == rightPos.front() - pos)
{
break;
}
else if (rightPos.empty() || (!leftPos.empty() && pos - leftPos.top() < rightPos.front() - pos))
{
// Left is closer
kolikot++;
askeleet += (pos - leftPos.top());
pos = leftPos.top();
leftPos.pop();
}
else
{
// Right is closer
kolikot++;
askeleet += (rightPos.front() - pos);
pos = rightPos.front();
rightPos.pop();
}
}
cout << askeleet << " " << kolikot << "\n";
// }
return 0;
}