84952024-01-19 10:43:03tamasmarkBináris fa magassága (50 pont)cpp17Time limit exceeded 20/50600ms3480 KiB
// Binarisfa2.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <deque>
#include <cmath>

using namespace std;

struct adat {
    int ertek, hossz=1;
};
deque<int>binaris;
void atalakit(int a)
{
    while (a > 0)
    {
        binaris.push_front(a % 2);
        a = a / 2;
    }
}
deque<adat>x;
int a, b,maxi,db,n,m;
void melysegi(int csp)
{
    db += x[csp].hossz;
    if (binaris.back() == 0&&binaris.size()>1)
    {
        binaris.pop_back();
        melysegi(csp / 2);
    }
    else if (binaris.back() == 1&&binaris.size()>1)
    {
        binaris.pop_back();
        melysegi((csp - 1) / 2);
    }
}
int main()
{
    cin >> n >> m;
    x.resize(pow(2, n));
    for (int i = 1; i <= m; ++i)
    {
        cin >> a >> b;
        x[a].hossz = b;
        maxi = 0;
        for (int j = pow(2, n - 1); j <= pow(2, n) - 1; ++j)
        {
            atalakit(j);
            db= -1;
            melysegi(j);
            binaris.clear();
            if (maxi < db) maxi = db;
        }

        cout << maxi << "\n";
    }
    return 0;
}
/*
3 5
2 6
4 3
6 7
5 4
2 1
*/
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/03ms1816 KiB
2Time limit exceeded0/0600ms1736 KiB
3Accepted2/24ms2220 KiB
4Accepted2/24ms2692 KiB
5Accepted2/24ms2616 KiB
6Accepted2/24ms2684 KiB
7Accepted3/37ms2804 KiB
8Accepted3/312ms2764 KiB
9Accepted3/320ms2892 KiB
10Accepted3/320ms3276 KiB
11Time limit exceeded0/2600ms2884 KiB
12Time limit exceeded0/2561ms2848 KiB
13Time limit exceeded0/2565ms2860 KiB
14Time limit exceeded0/2546ms2980 KiB
15Time limit exceeded0/2541ms2996 KiB
16Time limit exceeded0/2526ms3164 KiB
17Time limit exceeded0/2550ms3216 KiB
18Time limit exceeded0/2537ms3140 KiB
19Time limit exceeded0/2554ms3196 KiB
20Time limit exceeded0/3565ms3268 KiB
21Time limit exceeded0/3555ms3480 KiB
22Time limit exceeded0/3550ms3296 KiB
23Time limit exceeded0/3563ms3252 KiB