# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1107304 | debugDragon | Parking Problem (innopolis2021_final_A) | C++14 | 0 ms | 0 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 <string>
using namespace std;
void solveSubtask1(const string& parkingLine, const string& queue) {
int n = parkingLine.size();
int m = queue.size();
// Initialize a counter for consecutive two-zone vacant slots.
int two_zone_count = 0;
for (int i = 0; i + 1 < n; ++i) {
if (parkingLine[i] == '.' && parkingLine[i + 1] == '.') {
++two_zone_count;
++i; // Skip next zone as it's part of this two-zone slot
}
}
string result;
result += (two_zone_count > 0 ? 'Y' : 'N'); // Initial availability check
// Simulate the parking process for each vehicle in the queue
for (char vehicle : queue) {
if (vehicle == 'M') {
// Motorcycle takes a single vacant spot
if (two_zone_count > 0) {
// Find the first two-zone slot and place the motorcycle there
for (int i = 0; i < n; ++i) {
if (parkingLine[i] == '.' && parkingLine[i + 1] == '.') {
parkingLine[i] = 'X'; // Motorcycle occupies one spot in a two-zone slot
--two_zone_count;
break;
}
}
}
} else if (vehicle == 'C') {
// Car requires two consecutive vacant spots
if (two_zone_count > 0) {
--two_zone_count; // Use one two-zone slot for the car
} else {
result += 'N'; // No space left for a car
continue;
}
}
// Check if there are still two consecutive vacant zones
result += (two_zone_count > 0 ? 'Y' : 'N');
}
cout << result << endl;
}
int main() {
int t;
cin >> t;
while (t--) {
string parkingLine, queue;
cin >> parkingLine >> queue;
solveSubtask1(parkingLine, queue);
}
return 0;
}