123052024-12-11 18:27:21ercseferencBináris fa magassága (50 pont)cpp17Time limit exceeded 20/50600ms812 KiB
#include <iostream>
#include <cmath>
int szint(int n){
    int s=0;
    while(n!=0){
        n=n/2; s++;}
    return s;}
int polc(int n, int p){
    for(int i=0; i<p; i++){n=2*n+1;} return n;}
using namespace std;
int main()
{
    int n,m,cs,v,r,k,s,t=0;
    cin>>n; cin>>m;
    int p=pow(2,n);
    int a[p]; for(int i=2; i<p; i++){a[i]=1;}
    a[0]=0; a[1]=0;
    for(int i=0; i<m; i++){
        r=0;
        cin>>cs; cin>>v;
        a[cs]=v;
        for(int i=cs*pow(2,n-szint(cs)); i<=polc(cs,n-szint(cs)); i++){
            s=0; k=i;
            while(k!=0){
                s=s+a[k]; k=k/2;}
            if(s>r) r=s;}
        if(r>t)t=r;
        else{
            r=0;
            for(int i=pow(2,n-1); i<pow(2,n); i++){
                s=0; k=i;
                while(k!=0){
                    s=s+a[k]; k=k/2;}
                if(s>r) r=s;}
            t=r;}
        cout<<t<<endl;}
    return 0;}
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/01ms496 KiB
2Time limit exceeded0/0578ms568 KiB
3Accepted2/23ms320 KiB
4Accepted2/23ms320 KiB
5Accepted2/23ms320 KiB
6Accepted2/23ms320 KiB
7Accepted3/34ms548 KiB
8Accepted3/34ms332 KiB
9Accepted3/37ms320 KiB
10Accepted3/36ms320 KiB
11Time limit exceeded0/2598ms568 KiB
12Time limit exceeded0/2600ms644 KiB
13Time limit exceeded0/2600ms812 KiB
14Time limit exceeded0/2587ms568 KiB
15Time limit exceeded0/2578ms568 KiB
16Time limit exceeded0/2580ms568 KiB
17Time limit exceeded0/2598ms572 KiB
18Time limit exceeded0/2591ms568 KiB
19Time limit exceeded0/2583ms756 KiB
20Time limit exceeded0/3587ms568 KiB
21Time limit exceeded0/3600ms568 KiB
22Time limit exceeded0/3580ms568 KiB
23Time limit exceeded0/3587ms568 KiB