122262024-12-10 07:35:51madvirBináris fa magassága (50 pont)cpp17Time limit exceeded 20/50600ms780 KiB
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    int n, m, x, y, maxut;
    cin >> n >> m;
    vector<int> mag;
    int fel[65537];
    fill_n(fel,65537,1);
    int q=pow(2,n-1), w=pow(2, n), ut;
    for(int i=0; i<m; i++) {
        cin >> x >> y;
        fel[x]=y;
        maxut=0;
        for(int j=q; j<w; j++) {
            x=j;
            ut=0;
            //cout << "j=" << j << endl;
            while(x!=1) {
                ut+=fel[x];
                //cout << "ut=" <<ut << ", ";
                x=(x-x%2)/2;
                //cout << "x=" << x << endl;
            }
            if(ut>maxut) {
                maxut=ut;
            }
        }
        mag.push_back(maxut);
    }
    for(vector<int>::iterator ptr=mag.begin(); ptr!=mag.end(); ptr++) {
        cout << *ptr << endl;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/01ms756 KiB
2Time limit exceeded0/0586ms568 KiB
3Accepted2/23ms756 KiB
4Accepted2/23ms756 KiB
5Accepted2/23ms760 KiB
6Accepted2/23ms568 KiB
7Accepted3/33ms568 KiB
8Accepted3/34ms568 KiB
9Accepted3/34ms664 KiB
10Accepted3/34ms568 KiB
11Time limit exceeded0/2598ms568 KiB
12Time limit exceeded0/2600ms636 KiB
13Time limit exceeded0/2597ms652 KiB
14Time limit exceeded0/2583ms568 KiB
15Time limit exceeded0/2589ms748 KiB
16Time limit exceeded0/2593ms568 KiB
17Time limit exceeded0/2600ms568 KiB
18Time limit exceeded0/2592ms572 KiB
19Time limit exceeded0/2569ms780 KiB
20Time limit exceeded0/3600ms648 KiB
21Time limit exceeded0/3600ms568 KiB
22Time limit exceeded0/3587ms748 KiB
23Time limit exceeded0/3583ms568 KiB