193502025-12-04 21:48:57szabelrTáblajátékcpp17Futási hiba 46/502ms560 KiB
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int k, x, height = 0;
    vector<int> binary;
    cin >> k;
    for (int i = 0; i < k; i++)
    {
        cin >> x;
        if (x == 0) {
            height++;
            if (!binary.empty())
                binary.push_back(0);
        }
        if (x == 1) {
            height++;
            binary.push_back(1);
        }
        if (x == 2) {
            height--;
           binary.pop_back(); // Added safety check here just in case
        }
        if (x == 3) {
            int egyes = -1;
            // FIX 1: Add (int) cast to avoid crash when size is 0
            for (int y = (int)binary.size() - 1; y >= 0; y--)
            {
                if (binary[y] == 1)
                {
                    if (y == 0)
                    {
                        binary.pop_back(); // This logic is actually fine for your style!
                        egyes = y;
                        break;
                    }
                    else
                    {
                        binary[y] = 0;
                        egyes = y;
                        break;
                    }
                }
            }
            // FIX 1: Add (int) cast here too
            for (int y = egyes + 1; y <= (int)binary.size() - 1; y++)
                binary[y] = 1;

        }
        if (x == 4) {
            int nulla = -1;
            // FIX 1: Add (int) cast here too
            for (int y = (int)binary.size() - 1; y >= 0; y--)
            {
                if (binary[y] == 0)
                {
                    binary[y] = 1;
                    nulla = y;
                    break;
                }
            }
            if (nulla == -1) {
                // FIX 2: When expanding 0 -> 1, we must push 1, not 0.
                binary.push_back(1); 
                
                // FIX 1: Add (int) cast here too
                for (int y = 1; y < (int)binary.size() - 1; y++)
                {
                    binary[y] = 0;
                }
            }
            else
            {
                // FIX 1: Add (int) cast here too
                for (int y = nulla + 1; y <= (int)binary.size() - 1; y++)
                    binary[y] = 0;
            }
        }
    }
    cout << height << endl;
    if (binary.empty())
        cout << 0;
    for (int i = 0; i < binary.size(); i++)
    {
        cout << binary[i];
    }
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base46/50
1Elfogadva0/01ms508 KiB
2Elfogadva0/01ms316 KiB
3Elfogadva3/31ms316 KiB
4Elfogadva3/31ms316 KiB
5Elfogadva3/31ms316 KiB
6Elfogadva3/31ms316 KiB
7Elfogadva3/31ms384 KiB
8Elfogadva3/31ms316 KiB
9Elfogadva3/31ms316 KiB
10Elfogadva3/31ms316 KiB
11Elfogadva3/31ms316 KiB
12Elfogadva3/31ms316 KiB
13Elfogadva4/42ms560 KiB
14Elfogadva4/41ms316 KiB
15Elfogadva4/41ms316 KiB
16Elfogadva4/41ms316 KiB
17Futási hiba0/42ms316 KiB