86022024-01-23 09:03:01AzukitsuBináris fa magassága (50 pont)cpp17Time limit exceeded 20/50600ms10836 KiB
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int max_magassag(vector<int> fa, int length, int index) {
    if (index > length) {
        return 0;
    }
    int bal_index = index * 2;
    int jobb_index = bal_index + 1;
    return max(
               max_magassag(fa, length, bal_index) + fa[index],
               max_magassag(fa, length, jobb_index) + fa[index]
               );
}

int main()
{
    int N, M;
    cin >> N >> M;
    //cout << N << endl;
    int sum = 0;
    for (int i = 0; i < N; i++) {
        //cout << sum << " " << N << " " << i << endl;
        sum += pow(2, i);
    }
    //cout << sum << endl;
    vector<int> fa(sum+1, 1); //osszes elem hosszu, a szamok a magassagokat jelzik
    //cout << max_magassag(fa, sum, 1) << endl;
    int indexek[M];
    int valuek[M];
    for (int i = 0; i < M; i++) {
        int index, value;
        cin >> index >> value;
        indexek[i] = index;
        valuek[i] = value;
    }
    for (int i = 0; i < M; i++) {
        fa[indexek[i]] = valuek[i];
        cout << max_magassag(fa, sum, 1) - 1 << endl;
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/03ms1812 KiB
2Time limit exceeded0/0600ms9220 KiB
3Accepted2/24ms2324 KiB
4Accepted2/24ms2304 KiB
5Accepted2/24ms2428 KiB
6Accepted2/24ms2652 KiB
7Accepted3/312ms2888 KiB
8Accepted3/317ms2948 KiB
9Accepted3/335ms2956 KiB
10Accepted3/335ms2956 KiB
11Time limit exceeded0/2566ms10044 KiB
12Time limit exceeded0/2582ms10044 KiB
13Time limit exceeded0/2550ms10096 KiB
14Time limit exceeded0/2561ms10132 KiB
15Time limit exceeded0/2565ms10284 KiB
16Time limit exceeded0/2565ms10456 KiB
17Time limit exceeded0/2565ms10556 KiB
18Time limit exceeded0/2569ms10632 KiB
19Time limit exceeded0/2574ms10504 KiB
20Time limit exceeded0/3558ms10612 KiB
21Time limit exceeded0/3569ms10592 KiB
22Time limit exceeded0/3558ms10744 KiB
23Time limit exceeded0/3578ms10836 KiB