123072024-12-11 19:12:34ercseferencBináris fa magassága (50 pont)cpp17Time limit exceeded 20/50600ms756 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/01ms320 KiB
2Time limit exceeded0/0593ms568 KiB
3Accepted2/23ms320 KiB
4Accepted2/23ms320 KiB
5Accepted2/23ms320 KiB
6Accepted2/23ms320 KiB
7Accepted3/34ms320 KiB
8Accepted3/34ms504 KiB
9Accepted3/37ms500 KiB
10Accepted3/37ms324 KiB
11Time limit exceeded0/2578ms568 KiB
12Time limit exceeded0/2600ms568 KiB
13Time limit exceeded0/2600ms568 KiB
14Time limit exceeded0/2578ms568 KiB
15Time limit exceeded0/2600ms568 KiB
16Time limit exceeded0/2578ms568 KiB
17Time limit exceeded0/2578ms568 KiB
18Time limit exceeded0/2592ms568 KiB
19Time limit exceeded0/2583ms568 KiB
20Time limit exceeded0/3600ms756 KiB
21Time limit exceeded0/3600ms568 KiB
22Time limit exceeded0/3583ms568 KiB
23Time limit exceeded0/3592ms568 KiB