120062024-11-24 16:05:10banhelyiBináris fa magassága (50 pont)cpp17Wrong answer 0/50600ms756 KiB
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    int n = 0;
    int m = 0;
    cin >> n;
    cin >> m;
    long int a;
    long int b;

    unsigned long int fameret=((long int)1 << n) - 1;
    int *fa= new int[fameret];
    for(unsigned long int i=0; i < fameret; i++){
        fa[i] = 1;
    }

    unsigned long int levelmeret=(long int)1 << (n-1);
    //unsigned long int *level=new unsigned long int[levelmeret];
    //for(unsigned long int i=0; i < levelmeret; i++){
    //    level[i] = n-1;
    //}

    for(unsigned long int k=0; k < m; k++){
        cin >> a;
        cin >> b;

        fa[a-1] = b;
        
	unsigned long int legnagyobb = 0;

        for(unsigned long int i = levelmeret-1; i < fameret; i++){
	    unsigned long int level = i;
	    unsigned long int osszeg = 0;
	    while (level>0) {
		osszeg+=fa[level];
		level /= 2;
	    }
		
            if(osszeg > legnagyobb){
                legnagyobb = osszeg;
            }
        }

        cout << legnagyobb << "\n";

    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/01ms320 KiB
2Time limit exceeded0/0586ms568 KiB
3Wrong answer0/23ms320 KiB
4Wrong answer0/23ms320 KiB
5Wrong answer0/23ms320 KiB
6Wrong answer0/23ms320 KiB
7Wrong answer0/33ms320 KiB
8Wrong answer0/33ms320 KiB
9Wrong answer0/33ms320 KiB
10Wrong answer0/34ms500 KiB
11Time limit exceeded0/2600ms680 KiB
12Time limit exceeded0/2600ms568 KiB
13Time limit exceeded0/2598ms676 KiB
14Time limit exceeded0/2582ms568 KiB
15Time limit exceeded0/2584ms684 KiB
16Time limit exceeded0/2588ms756 KiB
17Time limit exceeded0/2588ms568 KiB
18Time limit exceeded0/2586ms572 KiB
19Time limit exceeded0/2580ms748 KiB
20Time limit exceeded0/3586ms568 KiB
21Time limit exceeded0/3586ms568 KiB
22Time limit exceeded0/3583ms568 KiB
23Time limit exceeded0/3583ms568 KiB