# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1107300 | debugDragon | Parking Problem (innopolis2021_final_A) | C++14 | 2065 ms | 888 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>
#include <vector>
using namespace std;
void solveSubtask1(const string& parkingLine, const string& queue) {
int n = parkingLine.size();
int m = queue.size();
vector<char> parking(n, '.'); // Initialize parking as vacant
string result;
// Check if Paulina can park without anyone from the queue entering
bool canParkInitially = (n >= 2);
result += (canParkInitially ? 'Y' : 'N');
for (char vehicle : 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
bool parked = false;
for (int i = 0; i + 1 < n; ++i) {
if (parking[i] == '.' && parking[i + 1] == '.') {
parking[i] = 'X';
parking[i + 1] = 'X';
parked = true;
break;
}
}
if (!parked) break; // No more space for cars
}
// Check if there are still two adjacent vacant spots for Paulina
bool canPark = false;
for (int i = 0; i + 1 < n; ++i) {
if (parking[i] == '.' && parking[i + 1] == '.') {
canPark = true;
break;
}
}
result += (canPark ? 'Y' : 'N');
}
cout << result << endl;
}
int main() {
int t;
cin >> t;
while (t--) {
string parkingLine, queue;
cin >> parkingLine >> queue;
solveSubtask1(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... |