# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1107304 | debugDragon | Parking Problem (innopolis2021_final_A) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}