답안 #1107300

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107300 2024-11-01T05:58:42 Z debugDragon Parking Problem (innopolis2021_final_A) C++14
0 / 100
2000 ms 888 KB
#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

Main.cpp: In function 'void solveSubtask1(const string&, const string&)':
Main.cpp:9:9: warning: unused variable 'm' [-Wunused-variable]
    9 |     int m = queue.size();
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2065 ms 836 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2047 ms 752 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2055 ms 888 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2065 ms 836 KB Time limit exceeded
2 Halted 0 ms 0 KB -