192582025-12-03 09:52:17szabelrBináris fa magassága (50 pont)cpp17Wrong answer 0/50118ms1076 KiB
#include <iostream>
#include <cmath>

using namespace std;
int check(int x,int dist[],int best[])
{
    while(x>0)
    {
        best[x]=max(dist[2*x]+best[x*2],dist[2*x+1]+best[x*2+1]);
        x=x/2;
    }
    return best[1];
}
int main()
{
    int dist[65537]{1};
    int best[65537];
    int n,m;
    cin>>n>>m;
    int i=1;
    int x=n-1;
    int a=1;
    while(i<pow(2,n))
    {
        if(i==pow(2,a))
        {
            x--;
            a++;
        }

        best[i]=x;
        i++;
    }
    for(int i=0; i<pow(2,n); i++)
    {
        dist[i]=0;
    }
    int b,c;
    for(int i=0; i<m; i++)
    {
        cin>>b>>c;
        dist[b]=c;
        cout<<check(b/2,dist,best);
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/01ms564 KiB
2Wrong answer0/0104ms960 KiB
3Wrong answer0/23ms748 KiB
4Wrong answer0/23ms564 KiB
5Wrong answer0/23ms564 KiB
6Wrong answer0/23ms656 KiB
7Wrong answer0/33ms604 KiB
8Wrong answer0/33ms564 KiB
9Wrong answer0/33ms644 KiB
10Wrong answer0/33ms564 KiB
11Wrong answer0/2118ms936 KiB
12Wrong answer0/2118ms916 KiB
13Wrong answer0/2114ms908 KiB
14Wrong answer0/2109ms824 KiB
15Wrong answer0/2115ms820 KiB
16Wrong answer0/2114ms820 KiB
17Wrong answer0/2114ms1004 KiB
18Wrong answer0/2104ms1076 KiB
19Wrong answer0/2109ms1072 KiB
20Wrong answer0/3114ms1004 KiB
21Wrong answer0/3115ms820 KiB
22Wrong answer0/3104ms936 KiB
23Wrong answer0/3104ms820 KiB