132542025-01-07 10:59:19gyjazminBináris fa magassága (50 pont)cpp17Time limit exceeded 20/50600ms864 KiB
#include <vector>
#include <iostream>
#include <cmath>
using namespace std;
int n, m,maxi;
vector<int> f;
void szamol(int k,int sz) {
    if (k * 2 < pow(2, n)) {
        szamol(k * 2, sz + f[k]);
        szamol(k * 2 + 1, sz + f[k]);
    }
    else {
        if (sz + f[k] > maxi) maxi = sz + f[k];
    }
}
int main()
{
    cin >> n >> m;
    f.resize(pow(2, n), 1);
    maxi = n-1;
    for (int i = 0; i < m; i++) {
        int cs = 0, h = 0;
        cin >> cs >> h;
        f[cs] = h;
        szamol(2,0);
        szamol(3, 0);
        cout << maxi << endl;
        maxi = n - 1;
    }
}
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/01ms316 KiB
2Time limit exceeded0/0583ms564 KiB
3Accepted2/23ms316 KiB
4Accepted2/23ms316 KiB
5Accepted2/23ms316 KiB
6Accepted2/23ms316 KiB
7Accepted3/34ms316 KiB
8Accepted3/37ms316 KiB
9Accepted3/310ms316 KiB
10Accepted3/310ms316 KiB
11Time limit exceeded0/2600ms564 KiB
12Time limit exceeded0/2598ms564 KiB
13Time limit exceeded0/2600ms564 KiB
14Time limit exceeded0/2583ms564 KiB
15Time limit exceeded0/2589ms864 KiB
16Time limit exceeded0/2600ms748 KiB
17Time limit exceeded0/2600ms564 KiB
18Time limit exceeded0/2588ms564 KiB
19Time limit exceeded0/2578ms564 KiB
20Time limit exceeded0/3600ms564 KiB
21Time limit exceeded0/3600ms564 KiB
22Time limit exceeded0/3591ms564 KiB
23Time limit exceeded0/3584ms564 KiB