#include <iostream>
#include <vector>
#include <string>
using namespace std;
bool canParkCar(const string &parking, int m) {
int n = parking.size();
vector<bool> occupied(n, false);
for (int i = 0; i < n; ++i) {
occupied[i] = parking[i] == 'X';
}
for (int i = 0; i < m; ++i) {
if (i >= n) break;
if (occupied[i]) continue;
// Check for motorcycle
if (occupied[i] == false) {
occupied[i] = true;
}
}
// Check for available parking for the car
for (int i = 0; i < n - 1; ++i) {
if (!occupied[i] && !occupied[i + 1]) {
return true;
}
}
return false;
}
string canParkSequence(string parking, string queue) {
string result;
int m = queue.size();
// Check before any vehicles enter
result += canParkCar(parking, 0) ? 'Y' : 'N';
for (int i = 0; i < m; ++i) {
if (queue[i] == 'M') {
parking += 'M'; // Simulate motorcycle parking
} else {
parking += 'C'; // Simulate car parking
}
if (canParkCar(parking, i + 1)) {
result += 'Y';
} else {
result += 'N';
}
}
return result;
}
int main() {
int t;
cin >> t;
while (t--) {
string parking, queue;
cin >> parking >> queue;
cout << canParkSequence(parking, queue) << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2061 ms |
748 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2048 ms |
740 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2066 ms |
800 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2061 ms |
748 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |