193412025-12-04 21:34:14szabelrTáblajátékcpp17Hibás válasz 30/502ms500 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); // Kept your logic (assuming safe)
            // Note: If you start at 0 and move 0, vector stays empty.
            // If the judge tests require 0->0 to be [0], unconditional push_back(0) is better.
             else binary.push_back(0); // Added this to be safe for root 0 move
        }
        if (x == 1) {
            height++;
            binary.push_back(1);
        }
        if (x == 2) {
            height--;
            if (!binary.empty()) binary.pop_back();
        }
        if (x == 3) {
            int egyes = -1;
            // CAST ADDED HERE
            for (int y = (int)binary.size() - 1; y >= 0; y--)
            {
                if (binary[y] == 1)
                {
                    if (y == 0)
                    {
                        binary.pop_back();
                        egyes = y;
                        break;
                    }
                    else
                    {
                        binary[y] = 0;
                        egyes = y;
                        break;
                    }
                }
            }
            // *** THE CRITICAL FIX IS HERE ***
            // (int)binary.size() prevents the loop from running to 4 billion when size is 0
            for (int y = egyes + 1; y <= (int)binary.size() - 1; y++)
                binary[y] = 1;

        }
        if (x == 4) {
            int nulla = -1;
            // CAST ADDED HERE
            for (int y = (int)binary.size() - 1; y >= 0; y--)
            {
                if (binary[y] == 0)
                {
                    binary[y] = 1;
                    nulla = y;
                    break;
                }
            }
            if (nulla == -1) {
                // Keep strictly to your logic logic
                binary.push_back(0); 
                // CAST ADDED HERE
                for (int y = 1; y < (int)binary.size() - 1; y++)
                {
                    binary[y] = 0;
                }
            }
            else
            {
                // CAST ADDED HERE
                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
base30/50
1Elfogadva0/01ms316 KiB
2Hibás válasz0/01ms316 KiB
3Részben helyes1/31ms320 KiB
4Elfogadva3/31ms316 KiB
5Részben helyes1/31ms316 KiB
6Részben helyes1/31ms316 KiB
7Részben helyes1/31ms316 KiB
8Részben helyes1/31ms316 KiB
9Részben helyes1/32ms316 KiB
10Részben helyes1/32ms316 KiB
11Elfogadva3/31ms316 KiB
12Elfogadva3/31ms316 KiB
13Elfogadva4/41ms316 KiB
14Elfogadva4/41ms316 KiB
15Részben helyes1/41ms316 KiB
16Részben helyes1/41ms500 KiB
17Elfogadva4/41ms316 KiB