# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1107291 | debugDragon | Parking Problem (innopolis2021_final_A) | C++14 | 2068 ms | 756 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <string>
using namespace std;
bool canParkCar(const vector<char>& parking) {
// Check if there are any two adjacent vacant spots
for (size_t i = 0; i + 1 < parking.size(); ++i) {
if (parking[i] == '.' && parking[i + 1] == '.') {
return true;
}
}
return false;
}
void solveTestCase(const string& parkingLine, const string& queue) {
int n = parkingLine.size();
int m = queue.size();
vector<char> parking(parkingLine.begin(), parkingLine.end());
string result;
// Check if Paulina can park without anyone from the queue entering
result += (canParkCar(parking) ? 'Y' : 'N');
for (char vehicle : queue) {
// Update the parking state based on the vehicle in the queue
if (vehicle == 'M') {
// Park a motorcycle in a single vacant spot
for (int i = 0; i < n; ++i) {
if (parking[i] == '.') {
parking[i] = 'X';
break;
}
}
} else if (vehicle == 'C') {
// Park a car in two adjacent vacant spots
for (int i = 0; i + 1 < n; ++i) {
if (parking[i] == '.' && parking[i + 1] == '.') {
parking[i] = 'X';
parking[i + 1] = 'X';
break;
}
}
}
// Check if Paulina can park after this vehicle enters
result += (canParkCar(parking) ? 'Y' : 'N');
}
cout << result << endl;
}
int main() {
int t;
cin >> t;
while (t--) {
string parkingLine, queue;
cin >> parkingLine >> queue;
solveTestCase(parkingLine, queue);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |