#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int base;
map<pair<ll, int>, ll> mem;
// 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;
if (mem.count({n, d})) {
return mem.at(pair<ll, int>(n, d));
}
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) {
res++;
}
return mem[pair<ll, int>(n, d)] = res;
}
int main() {
cin >> base;
vector<ll> budget(base);
for (auto &b : budget)
cin >> b;
auto is_enough = [&](ll 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 = 61; 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 | Wrong answer | 8ms | 3112 KiB | ||||
2 | Accepted | 3ms | 2260 KiB | ||||
3 | Accepted | 4ms | 2412 KiB | ||||
subtask2 | 0/25 | ||||||
4 | Wrong answer | 8ms | 3516 KiB | ||||
5 | Wrong answer | 8ms | 3616 KiB | ||||
6 | Wrong answer | 8ms | 3828 KiB | ||||
7 | Accepted | 3ms | 2960 KiB | ||||
8 | Accepted | 3ms | 3252 KiB | ||||
9 | Accepted | 4ms | 3384 KiB | ||||
10 | Wrong answer | 8ms | 4672 KiB | ||||
11 | Wrong answer | 6ms | 4284 KiB | ||||
12 | Wrong answer | 4ms | 4064 KiB | ||||
13 | Wrong answer | 6ms | 4408 KiB | ||||
14 | Accepted | 3ms | 4068 KiB | ||||
15 | Accepted | 3ms | 3984 KiB | ||||
16 | Accepted | 3ms | 3916 KiB | ||||
17 | Accepted | 3ms | 3980 KiB | ||||
18 | Accepted | 3ms | 4252 KiB | ||||
19 | Accepted | 3ms | 4200 KiB | ||||
subtask3 | 0/10 | ||||||
20 | Wrong answer | 8ms | 5408 KiB | ||||
21 | Wrong answer | 8ms | 5404 KiB | ||||
22 | Wrong answer | 8ms | 5396 KiB | ||||
23 | Wrong answer | 8ms | 5400 KiB | ||||
24 | Wrong answer | 8ms | 5392 KiB | ||||
subtask4 | 0/15 | ||||||
25 | Wrong answer | 8ms | 5620 KiB | ||||
26 | Wrong answer | 6ms | 5216 KiB | ||||
27 | Wrong answer | 6ms | 5072 KiB | ||||
28 | Wrong answer | 6ms | 5216 KiB | ||||
29 | Accepted | 4ms | 5116 KiB | ||||
30 | Accepted | 3ms | 4812 KiB | ||||
31 | Accepted | 4ms | 5048 KiB | ||||
32 | Accepted | 4ms | 5144 KiB | ||||
33 | Accepted | 4ms | 5152 KiB | ||||
subtask5 | 20/20 | ||||||
34 | Accepted | 3ms | 4944 KiB | ||||
35 | Accepted | 3ms | 5100 KiB | ||||
36 | Accepted | 4ms | 5260 KiB | ||||
37 | Accepted | 4ms | 5228 KiB | ||||
38 | Accepted | 4ms | 5236 KiB | ||||
39 | Accepted | 4ms | 5232 KiB | ||||
40 | Accepted | 4ms | 5280 KiB | ||||
41 | Accepted | 4ms | 5252 KiB | ||||
42 | Accepted | 4ms | 5492 KiB | ||||
subtask6 | 0/30 | ||||||
43 | Wrong answer | 8ms | 6316 KiB | ||||
44 | Wrong answer | 6ms | 5740 KiB | ||||
45 | Wrong answer | 6ms | 5724 KiB | ||||
46 | Wrong answer | 6ms | 5876 KiB | ||||
47 | Accepted | 4ms | 5484 KiB | ||||
48 | Accepted | 4ms | 5500 KiB | ||||
49 | Accepted | 4ms | 5412 KiB | ||||
50 | Accepted | 4ms | 5472 KiB | ||||
51 | Accepted | 4ms | 5536 KiB | ||||
52 | Wrong answer | 8ms | 6456 KiB | ||||
53 | Wrong answer | 6ms | 5948 KiB | ||||
54 | Wrong answer | 4ms | 5924 KiB | ||||
55 | Wrong answer | 6ms | 5936 KiB | ||||
56 | Accepted | 4ms | 5476 KiB | ||||
57 | Accepted | 4ms | 5496 KiB | ||||
58 | Accepted | 4ms | 5752 KiB | ||||
59 | Accepted | 4ms | 5452 KiB | ||||
60 | Accepted | 4ms | 5460 KiB |