83882024-01-15 13:22:42gonterarminBináris fa magassága (50 pont)cpp17Time limit exceeded 20/50600ms7300 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;


int main()
{
    int n,m;
    cin>>n>>m;
    int skh=pow(2,n-1);
    int g[n-1][skh][2];
    int akt=1,ue=1;
    for (int i = 0; i < n-1; i++)
    {
        for (int j = 0; j < skh; j++)
        {
            g[i][j][0]=1;
        }
        ue+=pow(2,i+1);
    }
    for (int i = n-1; i >= 0; i--)
    {
        int counter=0;
        for (int j = skh; j > 0 &&ue>1; j--)
        {
            g[i-1][j-1][1]=ue;
            counter++;
            if (counter==akt) {ue--;counter=0;}
        }
        akt+=akt;
    }
    for (int i = 0; i < m; i++)
    {
        int c,h;
        cin>>c>>h;
        for (int k=0;k<n-1;k++){
        for(int j=0;j<skh;j++) {
            if (g[k][j][1]==c) g[k][j][0]=h;
        }
        }
        int ma=0;
        int ho[skh];
        for (int k = 0; k < pow(2,n-1); k++)
        {
            ho[k]=0;
            for (int j = 0; j < n-1; j++)
            {
                ho[k]+=g[j][k][0];
            }
        }
        for (int j = 0; j < pow(2,n-1); j++) {
            if (ma<ho[j]) ma=ho[j];
        }
        cout<<ma<<endl;
    }
}
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/03ms1744 KiB
2Time limit exceeded0/0600ms5120 KiB
3Accepted2/24ms1996 KiB
4Accepted2/24ms2504 KiB
5Accepted2/24ms2472 KiB
6Accepted2/24ms2436 KiB
7Accepted3/37ms2688 KiB
8Accepted3/312ms2640 KiB
9Accepted3/316ms2796 KiB
10Accepted3/316ms2792 KiB
11Time limit exceeded0/2559ms6164 KiB
12Time limit exceeded0/2550ms6192 KiB
13Time limit exceeded0/2563ms6260 KiB
14Time limit exceeded0/2546ms6448 KiB
15Time limit exceeded0/2542ms6600 KiB
16Time limit exceeded0/2561ms6576 KiB
17Time limit exceeded0/2574ms6684 KiB
18Time limit exceeded0/2554ms6752 KiB
19Time limit exceeded0/2566ms6804 KiB
20Time limit exceeded0/3574ms6880 KiB
21Time limit exceeded0/3542ms6936 KiB
22Time limit exceeded0/3582ms7252 KiB
23Time limit exceeded0/3566ms7300 KiB