193492025-12-04 21:47:39szabelrTáblajátékcpp17Wrong answer 30/501ms508 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++;
            // We can leave this as is, but removing the check is safer for logic
            // if (!binary.empty()) binary.push_back(0); 
            // Better:
             binary.push_back(0);
        }
        if (x == 1) {
            height++;
            binary.push_back(1);
        }
        if (x == 2) {
            height--;
            if (!binary.empty()) binary.pop_back();
        }
        if (x == 3) {
            int egyes = -1;
            // No cast needed here (Assignment saves us)
            for (int y = 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;
                    }
                }
            }
            
            // *** CRITICAL CAST NEEDED HERE ***
            for (int y = egyes + 1; y <= (int)binary.size() - 1; y++)
                binary[y] = 1;
        }
        if (x == 4) {
            int nulla = -1;
            // No cast needed here (Assignment saves us)
            for (int y = binary.size() - 1; y >= 0; y--)
            {
                if (binary[y] == 0)
                {
                    binary[y] = 1;
                    nulla = y;
                    break;
                }
            }
            if (nulla == -1) {
                // FIXED: Must push 1, not 0
                binary.push_back(1); 
                
                // *** CRITICAL CAST NEEDED HERE ***
                for (int y = 1; y < (int)binary.size() - 1; y++)
                {
                    binary[y] = 0;
                }
            }
            else
            {
                // *** CRITICAL CAST NEEDED 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];
    }
}
SubtaskSumTestVerdictTimeMemory
base30/50
1Accepted0/01ms316 KiB
2Wrong answer0/01ms316 KiB
3Partially correct1/31ms316 KiB
4Accepted3/31ms316 KiB
5Partially correct1/31ms316 KiB
6Partially correct1/31ms316 KiB
7Partially correct1/31ms316 KiB
8Partially correct1/31ms316 KiB
9Partially correct1/31ms316 KiB
10Partially correct1/31ms316 KiB
11Accepted3/31ms316 KiB
12Accepted3/31ms508 KiB
13Accepted4/41ms316 KiB
14Accepted4/41ms316 KiB
15Partially correct1/41ms316 KiB
16Partially correct1/41ms324 KiB
17Accepted4/41ms316 KiB