#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int base;
// I have no idea how this works, just started messing around with formulas on
// OEIS and got this working
// calculates the number of `d` digits used from `1..n`
ll pog(ll n, int d) {
if (n <= 0)
return 0;
ll r = n % base;
ll q = n / base;
ll res = q + (r + 1) * pog(q, d) + (base - r - 1) * pog(q - 1, d);
if (d != 0 && r >= d)
return res + 1;
return res;
}
int main() {
cin >> base;
vector<ll> budget(base);
for (auto &b : budget)
cin >> b;
auto is_enough = [&](int n) {
for (int i = 0; i < base; i++) {
ll a = pog(n, i);
if (a > budget[i])
return false;
}
return true;
};
ll curr = 0;
for (int i = 20; i >= 0; i--) {
ll next = curr + (1ll << i);
if (is_enough(next)) {
curr = next;
}
}
cout << curr;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 32ms | 1732 KiB | ||||
2 | Accepted | 3ms | 1856 KiB | ||||
3 | Wrong answer | 3ms | 2096 KiB | ||||
subtask2 | 25/25 | ||||||
4 | Accepted | 32ms | 2344 KiB | ||||
5 | Accepted | 35ms | 2588 KiB | ||||
6 | Accepted | 34ms | 2768 KiB | ||||
7 | Accepted | 3ms | 2924 KiB | ||||
8 | Accepted | 3ms | 3136 KiB | ||||
9 | Accepted | 3ms | 3352 KiB | ||||
10 | Accepted | 34ms | 3556 KiB | ||||
11 | Accepted | 3ms | 3812 KiB | ||||
12 | Accepted | 3ms | 3888 KiB | ||||
13 | Accepted | 3ms | 4020 KiB | ||||
14 | Accepted | 3ms | 4196 KiB | ||||
15 | Accepted | 3ms | 4308 KiB | ||||
16 | Accepted | 3ms | 4364 KiB | ||||
17 | Accepted | 3ms | 4240 KiB | ||||
18 | Accepted | 2ms | 4248 KiB | ||||
19 | Accepted | 3ms | 4480 KiB | ||||
subtask3 | 0/10 | ||||||
20 | Time limit exceeded | 261ms | 4432 KiB | ||||
21 | Time limit exceeded | 263ms | 4452 KiB | ||||
22 | Time limit exceeded | 268ms | 4328 KiB | ||||
23 | Accepted | 30ms | 4456 KiB | ||||
24 | Time limit exceeded | 300ms | 4564 KiB | ||||
subtask4 | 0/15 | ||||||
25 | Time limit exceeded | 264ms | 4536 KiB | ||||
26 | Wrong answer | 14ms | 4668 KiB | ||||
27 | Wrong answer | 4ms | 4668 KiB | ||||
28 | Wrong answer | 4ms | 4700 KiB | ||||
29 | Wrong answer | 3ms | 4680 KiB | ||||
30 | Accepted | 3ms | 4680 KiB | ||||
31 | Wrong answer | 3ms | 4672 KiB | ||||
32 | Wrong answer | 3ms | 4672 KiB | ||||
33 | Wrong answer | 3ms | 4796 KiB | ||||
subtask5 | 0/20 | ||||||
34 | Accepted | 3ms | 4796 KiB | ||||
35 | Accepted | 2ms | 4816 KiB | ||||
36 | Wrong answer | 3ms | 4788 KiB | ||||
37 | Wrong answer | 3ms | 4796 KiB | ||||
38 | Wrong answer | 3ms | 4916 KiB | ||||
39 | Wrong answer | 3ms | 4800 KiB | ||||
40 | Wrong answer | 3ms | 4796 KiB | ||||
41 | Wrong answer | 3ms | 4676 KiB | ||||
42 | Wrong answer | 3ms | 4788 KiB | ||||
subtask6 | 0/30 | ||||||
43 | Time limit exceeded | 300ms | 4764 KiB | ||||
44 | Wrong answer | 14ms | 4816 KiB | ||||
45 | Wrong answer | 4ms | 4792 KiB | ||||
46 | Wrong answer | 4ms | 4792 KiB | ||||
47 | Wrong answer | 3ms | 4788 KiB | ||||
48 | Wrong answer | 3ms | 4672 KiB | ||||
49 | Wrong answer | 3ms | 4672 KiB | ||||
50 | Wrong answer | 3ms | 4676 KiB | ||||
51 | Wrong answer | 3ms | 4672 KiB | ||||
52 | Accepted | 32ms | 4672 KiB | ||||
53 | Wrong answer | 14ms | 4796 KiB | ||||
54 | Wrong answer | 4ms | 4676 KiB | ||||
55 | Wrong answer | 4ms | 4788 KiB | ||||
56 | Wrong answer | 3ms | 4788 KiB | ||||
57 | Wrong answer | 3ms | 4676 KiB | ||||
58 | Wrong answer | 3ms | 4672 KiB | ||||
59 | Wrong answer | 3ms | 4676 KiB | ||||
60 | Wrong answer | 3ms | 4788 KiB |