Task: | Robotti |
Sender: | Interaalimato |
Submission time: | 2024-10-28 11:05:59 +0200 |
Language: | C++ (C++20) |
Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:10:5: error: 'vector' was not declared in this scope 10 | vector<int> locations; | ^~~~~~ input/code.cpp:2:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'? 1 | #include <iostream> +++ |+#include <vector> 2 | input/code.cpp:10:12: error: expected primary-expression before 'int' 10 | vector<int> locations; | ^~~ input/code.cpp:18:13: error: 'locations' was not declared in this scope 18 | locations.push_back(i); | ^~~~~~~~~ input/code.cpp:25:12: error: 'locations' was not declared in this scope 25 | while (locations.size() > 0) | ^~~~~~~~~
Code
#include <iostream> using namespace std; int main() { int n; string huoneet; cin >> n >> huoneet; vector<int> locations; int pos; int askeleet = 0; int kolikot = 0; for (int i = 1; i < n + 1; i++) { if (huoneet.at(i - 1) == '*') { locations.push_back(i); } else if (huoneet.at(i - 1) == 'R') { pos = i; } } while (locations.size() > 0) { int start = 0; int m = locations.size() - 1; int end = m; int dist = m + 1; int nearestIdx = 0; while (start <= end) { int mid = (start + end) / 2; if ((locations[mid] < pos) && (mid == m + 1 || locations[mid + 1] > pos)) { dist = pos - locations[mid]; nearestIdx = mid; break; } else if ((locations[mid] > pos) && (mid == 0 || locations[mid - 1] < pos)) { dist = locations[mid] - pos; nearestIdx = mid; break; } if (locations[mid] > pos) { end = mid - 1; } else if (locations[mid] < pos) { start = mid + 1; } } if ((nearestIdx < m && dist == locations[nearestIdx + 1] - pos) || (nearestIdx > 0 && dist == pos - locations[nearestIdx - 1])) { break; } kolikot++; askeleet += dist; pos = locations[nearestIdx]; locations.erase(locations.begin() + nearestIdx); } cout << askeleet << " " << kolikot << "\n"; return 0; }