123232024-12-12 11:53:01madvirBináris fa magassága (50 pont)cpp11Time limit exceeded 20/50600ms760 KiB
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    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/01ms572 KiB
2Time limit exceeded0/0577ms568 KiB
3Accepted2/23ms748 KiB
4Accepted2/23ms568 KiB
5Accepted2/22ms568 KiB
6Accepted2/22ms688 KiB
7Accepted3/33ms568 KiB
8Accepted3/33ms568 KiB
9Accepted3/34ms684 KiB
10Accepted3/34ms568 KiB
11Time limit exceeded0/2586ms568 KiB
12Time limit exceeded0/2587ms568 KiB
13Time limit exceeded0/2600ms568 KiB
14Time limit exceeded0/2583ms568 KiB
15Time limit exceeded0/2583ms760 KiB
16Time limit exceeded0/2584ms676 KiB
17Time limit exceeded0/2600ms568 KiB
18Time limit exceeded0/2588ms568 KiB
19Time limit exceeded0/2583ms568 KiB
20Time limit exceeded0/3586ms572 KiB
21Time limit exceeded0/3598ms676 KiB
22Time limit exceeded0/3580ms568 KiB
23Time limit exceeded0/3583ms568 KiB