193432025-12-04 21:36:06szabelrTáblajátékcpp17Elfogadva 50/501ms508 KiB
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int k, x;
    // We don't need 'height'. The vector size IS the height.
    vector<int> binary;
    cin >> k;
    for (int i = 0; i < k; i++)
    {
        cin >> x;
        if (x == 0) {
            // Move Down-Left: Just add a 0
            binary.push_back(0);
        }
        else if (x == 1) {
            // Move Down-Right: Just add a 1
            binary.push_back(1);
        }
        else if (x == 2) {
            // Move Up: Remove the last step
            if (!binary.empty()) binary.pop_back();
        }
        else if (x == 3) {
            // Move Left: Subtract 1
            // FIX: Don't pop_back. Just flip bits. 
            // We trust the input is valid, so we don't need to check y==0 specifically.
            for (int y = binary.size() - 1; y >= 0; y--)
            {
                if (binary[y] == 1)
                {
                    binary[y] = 0; // Flip 1 to 0
                    // Set everything to the right to 1
                    for (int z = y + 1; z < binary.size(); z++) 
                        binary[z] = 1;
                    break;
                }
            }
        }
        else if (x == 4) {
            // Move Right: Add 1
            // FIX: Don't push_back. Valid moves mean we stay in the same row.
            for (int y = binary.size() - 1; y >= 0; y--)
            {
                if (binary[y] == 0)
                {
                    binary[y] = 1; // Flip 0 to 1
                    // Set everything to the right to 0
                    for (int z = y + 1; z < binary.size(); z++) 
                        binary[z] = 0;
                    break;
                }
            }
        }
    }

    // OUTPUT SECTION
    
    // 1. Print the row number
    cout << binary.size() << endl;

    // 2. Print the binary number (Skipping leading zeros)
    // Example: If vector is [0, 1, 1], we print "11".
    
    bool hasStartedPrinting = false;
    for (int i = 0; i < binary.size(); i++)
    {
        if (binary[i] == 1) hasStartedPrinting = true;
        
        if (hasStartedPrinting) {
            cout << binary[i];
        }
    }
    
    // Edge case: If the number is 0 (vector is all zeros or empty), nothing printed above.
    // So we print a single 0.
    if (!hasStartedPrinting) {
        cout << 0;
    }
    
    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/01ms316 KiB
2Elfogadva0/01ms316 KiB
3Elfogadva3/31ms316 KiB
4Elfogadva3/31ms316 KiB
5Elfogadva3/31ms316 KiB
6Elfogadva3/31ms316 KiB
7Elfogadva3/31ms316 KiB
8Elfogadva3/31ms400 KiB
9Elfogadva3/31ms508 KiB
10Elfogadva3/31ms316 KiB
11Elfogadva3/31ms316 KiB
12Elfogadva3/31ms316 KiB
13Elfogadva4/41ms316 KiB
14Elfogadva4/41ms324 KiB
15Elfogadva4/41ms316 KiB
16Elfogadva4/41ms508 KiB
17Elfogadva4/41ms316 KiB