#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 = 30; 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 | Time limit exceeded | 272ms | 1784 KiB | ||||
2 | Accepted | 3ms | 2064 KiB | ||||
3 | Wrong answer | 13ms | 2272 KiB | ||||
subtask2 | 0/25 | ||||||
4 | Time limit exceeded | 261ms | 1748 KiB | ||||
5 | Time limit exceeded | 272ms | 2656 KiB | ||||
6 | Time limit exceeded | 259ms | 2856 KiB | ||||
7 | Accepted | 3ms | 2972 KiB | ||||
8 | Accepted | 3ms | 2936 KiB | ||||
9 | Accepted | 3ms | 3064 KiB | ||||
10 | Time limit exceeded | 300ms | 3276 KiB | ||||
11 | Accepted | 29ms | 3392 KiB | ||||
12 | Accepted | 4ms | 3488 KiB | ||||
13 | Accepted | 3ms | 3704 KiB | ||||
14 | Accepted | 3ms | 3912 KiB | ||||
15 | Accepted | 3ms | 4124 KiB | ||||
16 | Accepted | 3ms | 4204 KiB | ||||
17 | Accepted | 3ms | 4236 KiB | ||||
18 | Accepted | 3ms | 4308 KiB | ||||
19 | Accepted | 3ms | 4312 KiB | ||||
subtask3 | 0/10 | ||||||
20 | Time limit exceeded | 280ms | 4516 KiB | ||||
21 | Time limit exceeded | 259ms | 4632 KiB | ||||
22 | Time limit exceeded | 268ms | 4732 KiB | ||||
23 | Time limit exceeded | 247ms | 4616 KiB | ||||
24 | Time limit exceeded | 248ms | 4496 KiB | ||||
subtask4 | 0/15 | ||||||
25 | Time limit exceeded | 263ms | 4628 KiB | ||||
26 | Time limit exceeded | 268ms | 4600 KiB | ||||
27 | Wrong answer | 115ms | 4516 KiB | ||||
28 | Wrong answer | 37ms | 4640 KiB | ||||
29 | Wrong answer | 17ms | 4764 KiB | ||||
30 | Accepted | 3ms | 4736 KiB | ||||
31 | Wrong answer | 9ms | 4844 KiB | ||||
32 | Wrong answer | 8ms | 4732 KiB | ||||
33 | Wrong answer | 8ms | 4728 KiB | ||||
subtask5 | 0/20 | ||||||
34 | Accepted | 3ms | 4728 KiB | ||||
35 | Accepted | 3ms | 4728 KiB | ||||
36 | Wrong answer | 8ms | 4736 KiB | ||||
37 | Wrong answer | 8ms | 4736 KiB | ||||
38 | Wrong answer | 8ms | 4736 KiB | ||||
39 | Wrong answer | 8ms | 4732 KiB | ||||
40 | Wrong answer | 8ms | 4860 KiB | ||||
41 | Wrong answer | 8ms | 5076 KiB | ||||
42 | Wrong answer | 8ms | 5192 KiB | ||||
subtask6 | 0/30 | ||||||
43 | Time limit exceeded | 250ms | 5060 KiB | ||||
44 | Time limit exceeded | 248ms | 5172 KiB | ||||
45 | Wrong answer | 115ms | 5152 KiB | ||||
46 | Wrong answer | 37ms | 5156 KiB | ||||
47 | Wrong answer | 16ms | 5160 KiB | ||||
48 | Wrong answer | 13ms | 5156 KiB | ||||
49 | Wrong answer | 9ms | 5180 KiB | ||||
50 | Wrong answer | 8ms | 5168 KiB | ||||
51 | Wrong answer | 8ms | 5168 KiB | ||||
52 | Time limit exceeded | 300ms | 5024 KiB | ||||
53 | Time limit exceeded | 263ms | 5024 KiB | ||||
54 | Wrong answer | 115ms | 5156 KiB | ||||
55 | Wrong answer | 37ms | 5296 KiB | ||||
56 | Wrong answer | 16ms | 5280 KiB | ||||
57 | Wrong answer | 13ms | 5168 KiB | ||||
58 | Wrong answer | 9ms | 5268 KiB | ||||
59 | Wrong answer | 8ms | 5268 KiB | ||||
60 | Wrong answer | 8ms | 5268 KiB |