50332023-04-10 10:31:03horvathabelHázszámokcpp17Time limit exceeded 0/100298ms5624 KiB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
vector<int>darab;
int n;
bool check(int x){
    int a=x;
    vector<int> valt;
    vector<int> db;
    db.resize(n,0);
    while (x>0){
        valt.push_back(x%n);
        x/=n;
    }
    int kell=pow(n,valt.size()-1);

    reverse(valt.begin(), valt.end());
    for (int i=0; i<n;i++){
        db[i]=kell;
    }
    int cnt=a-(kell-1);
    int szamlalo=1;
    for (int i=1; i<=valt.size();i++){
        int h=0;
        db[0]-=szamlalo;

        if (i==valt.size()){
            h=1;
            db[0]+=szamlalo;
        }
        for (int j=1; j<=cnt;j++){
            db[h]++;
            if (j%szamlalo==0){
                h++;
                if (h==n) h=0;
            }
        }
        szamlalo*=n;
    }
    for (int i=0; i<n;i++){
        if (db[i]>darab[i]) return false;
    }
    return true;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;

    for (int i=0; i<n;i++){
        int x;
        cin>>x;
        darab.push_back(x);
    }
    int l=0, r=1e12;
    while (l<r){
        int m=(l+r)/2;
        if (check(m)){
            l=m;
        }
        else{
            r=m;
        }
        cout<<r<<" "<<m<<endl;
    }
    cout<<r<<endl;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Time limit exceeded246ms1080 KiB
2Time limit exceeded264ms1256 KiB
3Time limit exceeded263ms1556 KiB
subtask20/25
4Time limit exceeded280ms2420 KiB
5Time limit exceeded264ms2636 KiB
6Time limit exceeded273ms3024 KiB
7Time limit exceeded298ms3168 KiB
8Time limit exceeded256ms3240 KiB
9Time limit exceeded263ms3472 KiB
10Time limit exceeded268ms2748 KiB
11Time limit exceeded264ms3716 KiB
12Time limit exceeded247ms3788 KiB
13Time limit exceeded275ms3784 KiB
14Time limit exceeded263ms3824 KiB
15Time limit exceeded284ms3824 KiB
16Time limit exceeded284ms3968 KiB
17Time limit exceeded250ms4208 KiB
18Time limit exceeded280ms4340 KiB
19Time limit exceeded244ms4452 KiB
subtask30/10
20Time limit exceeded287ms4536 KiB
21Time limit exceeded203ms4652 KiB
22Time limit exceeded259ms4664 KiB
23Time limit exceeded268ms4668 KiB
24Time limit exceeded268ms4760 KiB
subtask40/15
25Time limit exceeded256ms4752 KiB
26Time limit exceeded272ms4760 KiB
27Time limit exceeded273ms4756 KiB
28Time limit exceeded259ms5036 KiB
29Time limit exceeded268ms5084 KiB
30Time limit exceeded256ms5092 KiB
31Time limit exceeded268ms5212 KiB
32Time limit exceeded280ms5288 KiB
33Time limit exceeded263ms5424 KiB
subtask50/20
34Time limit exceeded280ms5320 KiB
35Time limit exceeded275ms5208 KiB
36Time limit exceeded268ms5204 KiB
37Time limit exceeded263ms5212 KiB
38Time limit exceeded275ms5212 KiB
39Time limit exceeded236ms5324 KiB
40Time limit exceeded280ms5432 KiB
41Time limit exceeded244ms5432 KiB
42Time limit exceeded268ms5324 KiB
subtask60/30
43Time limit exceeded239ms5340 KiB
44Time limit exceeded252ms5248 KiB
45Time limit exceeded246ms4664 KiB
46Time limit exceeded275ms5352 KiB
47Time limit exceeded280ms5468 KiB
48Time limit exceeded279ms5368 KiB
49Time limit exceeded263ms5368 KiB
50Time limit exceeded275ms5476 KiB
51Time limit exceeded268ms5376 KiB
52Time limit exceeded272ms4688 KiB
53Time limit exceeded280ms5624 KiB
54Time limit exceeded272ms5592 KiB
55Time limit exceeded270ms5404 KiB
56Time limit exceeded254ms5468 KiB
57Time limit exceeded263ms5476 KiB
58Time limit exceeded268ms5480 KiB
59Time limit exceeded264ms5488 KiB
60Time limit exceeded273ms5392 KiB