Submission #1107304

# Submission time Handle Problem Language Result Execution time Memory
1107304 2024-11-01T06:00:16 Z debugDragon Parking Problem (innopolis2021_final_A) C++14
Compilation error
0 ms 0 KB
#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;
}

Compilation message

Main.cpp: In function 'void solveSubtask1(const string&, const string&)':
Main.cpp:30:40: error: assignment of read-only location '(& parkingLine)->std::__cxx11::basic_string<char>::operator[](((std::__cxx11::basic_string<char>::size_type)i))'
   30 |                         parkingLine[i] = 'X';  // Motorcycle occupies one spot in a two-zone slot
Main.cpp:8:9: warning: unused variable 'm' [-Wunused-variable]
    8 |     int m = queue.size();
      |         ^