52422023-04-23 17:09:19ZsofiaKeresztelyHázszámokcpp14Wrong answer 0/1003ms5392 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> lim;
int k;

vector<int> convert(ll n){
    vector<int> r;
    while (n){
        r.push_back(n % k);
        n /= k;
    }
    return r;
}

bool ok(ll m, vector<int> n){
    vector<ll> req(k, 0);
    int power = 1;
    for (int i=0; i<n.size(); i++){
        req[0] += power * (m / (power * k));
        if (n[i] == 0) req[0] -= power;
        if (req[0] > lim[0]) return 0;
        for (int j=1; j<n[i]; j++){
            req[j] += power * (m / (power * k) + 1);
            if (req[j] > lim[j]) return 0;
        }
        for (int j=n[i]; j<k; j++){
            req[j] += power * (m / (power * k));
            if (req[j] > lim[j]) return 0;
        }
        power *= 3;
    }
    return true;
}

int main()
{
    cin >> k;
    lim.resize(k);
    for (ll &x : lim){
        cin >> x;
    }
    ll l = 2, r = 1e14;
    while (l + 1 < r){
        ll m = (l + r) / 2;
        if (ok(m, convert(m))){
            l = m;
        }
        else{
            r = m;
        }
    }
    cout << l - 1;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1808 KiB
2Wrong answer3ms2000 KiB
3Wrong answer3ms2216 KiB
subtask20/25
4Wrong answer3ms2428 KiB
5Wrong answer3ms2792 KiB
6Wrong answer3ms2736 KiB
7Wrong answer3ms2968 KiB
8Wrong answer3ms3176 KiB
9Wrong answer3ms3428 KiB
10Wrong answer3ms3600 KiB
11Wrong answer3ms3692 KiB
12Wrong answer3ms3692 KiB
13Wrong answer3ms3820 KiB
14Wrong answer3ms4028 KiB
15Wrong answer3ms4164 KiB
16Wrong answer2ms4244 KiB
17Wrong answer3ms4324 KiB
18Wrong answer3ms4324 KiB
19Wrong answer2ms4320 KiB
subtask30/10
20Wrong answer3ms4440 KiB
21Wrong answer3ms4436 KiB
22Wrong answer3ms4432 KiB
23Wrong answer3ms4460 KiB
24Wrong answer3ms4536 KiB
subtask40/15
25Wrong answer3ms4424 KiB
26Wrong answer2ms4428 KiB
27Wrong answer3ms4552 KiB
28Wrong answer2ms4548 KiB
29Wrong answer3ms4800 KiB
30Wrong answer2ms4892 KiB
31Wrong answer2ms4976 KiB
32Wrong answer2ms4944 KiB
33Wrong answer2ms4944 KiB
subtask50/20
34Wrong answer3ms4944 KiB
35Wrong answer3ms4944 KiB
36Wrong answer3ms4948 KiB
37Wrong answer3ms5056 KiB
38Wrong answer2ms5060 KiB
39Wrong answer2ms5176 KiB
40Wrong answer3ms5056 KiB
41Wrong answer2ms5172 KiB
42Wrong answer2ms5288 KiB
subtask60/30
43Wrong answer3ms5168 KiB
44Wrong answer3ms5060 KiB
45Wrong answer3ms5176 KiB
46Wrong answer2ms4944 KiB
47Wrong answer3ms5060 KiB
48Wrong answer3ms5060 KiB
49Wrong answer3ms5056 KiB
50Wrong answer3ms5184 KiB
51Wrong answer2ms5268 KiB
52Wrong answer2ms5268 KiB
53Wrong answer2ms5388 KiB
54Wrong answer2ms5272 KiB
55Wrong answer2ms5392 KiB
56Wrong answer2ms5272 KiB
57Wrong answer3ms5152 KiB
58Wrong answer2ms5160 KiB
59Wrong answer2ms5156 KiB
60Wrong answer2ms5272 KiB