193422025-12-04 21:35:52szabelrHírlánccpp17Wrong answer 0/8068ms576 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer1ms508 KiB
subtask20/20
2Wrong answer1ms316 KiB
3Wrong answer1ms400 KiB
4Wrong answer1ms316 KiB
5Wrong answer1ms316 KiB
6Wrong answer2ms512 KiB
7Wrong answer2ms316 KiB
8Wrong answer2ms512 KiB
9Wrong answer2ms316 KiB
10Wrong answer1ms316 KiB
11Wrong answer1ms316 KiB
12Wrong answer1ms316 KiB
subtask30/18
13Wrong answer68ms392 KiB
14Wrong answer68ms396 KiB
15Wrong answer68ms396 KiB
16Wrong answer67ms560 KiB
17Wrong answer68ms316 KiB
18Wrong answer68ms404 KiB
19Wrong answer68ms508 KiB
20Wrong answer68ms316 KiB
21Wrong answer68ms576 KiB
22Wrong answer68ms400 KiB
subtask40/42
23Wrong answer2ms316 KiB
24Wrong answer1ms316 KiB
25Wrong answer1ms400 KiB
26Wrong answer1ms316 KiB
27Wrong answer1ms316 KiB
28Wrong answer2ms512 KiB
29Wrong answer2ms316 KiB
30Wrong answer2ms512 KiB
31Wrong answer2ms316 KiB
32Wrong answer1ms316 KiB
33Wrong answer1ms316 KiB
34Wrong answer1ms316 KiB
35Wrong answer68ms392 KiB
36Wrong answer68ms396 KiB
37Wrong answer68ms396 KiB
38Wrong answer67ms560 KiB
39Wrong answer68ms316 KiB
40Wrong answer68ms404 KiB
41Wrong answer68ms508 KiB
42Wrong answer68ms316 KiB
43Wrong answer68ms576 KiB
44Wrong answer68ms400 KiB
45Wrong answer68ms508 KiB
46Wrong answer68ms316 KiB
47Wrong answer68ms508 KiB
48Wrong answer68ms404 KiB
49Wrong answer68ms324 KiB
50Wrong answer68ms328 KiB
51Wrong answer68ms328 KiB
52Wrong answer68ms328 KiB
53Wrong answer68ms508 KiB
54Wrong answer68ms328 KiB