123082024-12-11 19:13:54ercseferencBináris fa magassága (50 pont)cpp17Wrong answer 0/50600ms968 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,k,r;
    int c=pow(2,n-1)-1;
    cin>>n; cin>>m;
    int p=pow(2,n-1)+1;
    int a[p]; for(int i=1; i<=p; i++){a[i]=n-1;}
    int q=pow(2,n);
    int b[q]; for(int i=2; i<q; i++){b[i]=1;}
    a[0]=0; b[0]=0; b[1]=0;
    for(int i=0; i<m; i++){
        cin>>cs; cin>>v;
        k=v-b[cs];
        b[cs]=v;
        for(int j=cs*pow(2,n-szint(cs))-c; j<=polc(cs,n-szint(cs))-c; j++)
            {a[i]=a[i]+k;}
        r=0;
        for(int j=1; j<p;j++){if(a[j]>r)r=a[j];}
        cout<<r<<endl;}
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/01ms320 KiB
2Time limit exceeded0/0584ms824 KiB
3Runtime error0/21ms320 KiB
4Time limit exceeded0/2584ms320 KiB
5Runtime error0/21ms320 KiB
6Runtime error0/21ms500 KiB
7Runtime error0/31ms396 KiB
8Runtime error0/31ms500 KiB
9Runtime error0/31ms320 KiB
10Runtime error0/32ms320 KiB
11Time limit exceeded0/2592ms968 KiB
12Time limit exceeded0/2600ms824 KiB
13Time limit exceeded0/2580ms824 KiB
14Time limit exceeded0/2589ms568 KiB
15Time limit exceeded0/2583ms792 KiB
16Time limit exceeded0/2600ms792 KiB
17Time limit exceeded0/2578ms792 KiB
18Time limit exceeded0/2573ms784 KiB
19Time limit exceeded0/2589ms824 KiB
20Time limit exceeded0/3574ms824 KiB
21Time limit exceeded0/3598ms788 KiB
22Time limit exceeded0/3575ms796 KiB
23Time limit exceeded0/3583ms756 KiB