#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 = 60; 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 | 3084 KiB | ||||
2 | Accepted | 3ms | 2276 KiB | ||||
3 | Accepted | 4ms | 2632 KiB | ||||
subtask2 | 0/25 | ||||||
4 | Wrong answer | 8ms | 3700 KiB | ||||
5 | Wrong answer | 8ms | 4216 KiB | ||||
6 | Wrong answer | 7ms | 4136 KiB | ||||
7 | Accepted | 3ms | 3124 KiB | ||||
8 | Accepted | 3ms | 3300 KiB | ||||
9 | Accepted | 3ms | 3396 KiB | ||||
10 | Wrong answer | 7ms | 4580 KiB | ||||
11 | Wrong answer | 6ms | 4096 KiB | ||||
12 | Accepted | 3ms | 3472 KiB | ||||
13 | Accepted | 3ms | 3900 KiB | ||||
14 | Accepted | 3ms | 4132 KiB | ||||
15 | Accepted | 3ms | 4004 KiB | ||||
16 | Accepted | 3ms | 4064 KiB | ||||
17 | Accepted | 3ms | 4056 KiB | ||||
18 | Accepted | 3ms | 4052 KiB | ||||
19 | Accepted | 3ms | 4196 KiB | ||||
subtask3 | 0/10 | ||||||
20 | Wrong answer | 7ms | 5240 KiB | ||||
21 | Wrong answer | 7ms | 5360 KiB | ||||
22 | Wrong answer | 8ms | 5360 KiB | ||||
23 | Wrong answer | 7ms | 5492 KiB | ||||
24 | Wrong answer | 7ms | 5308 KiB | ||||
subtask4 | 0/15 | ||||||
25 | Wrong answer | 7ms | 5436 KiB | ||||
26 | Wrong answer | 6ms | 5204 KiB | ||||
27 | Accepted | 4ms | 4932 KiB | ||||
28 | Accepted | 4ms | 4932 KiB | ||||
29 | Accepted | 4ms | 4968 KiB | ||||
30 | Accepted | 3ms | 4696 KiB | ||||
31 | Accepted | 4ms | 5072 KiB | ||||
32 | Accepted | 4ms | 5088 KiB | ||||
33 | Accepted | 4ms | 5088 KiB | ||||
subtask5 | 20/20 | ||||||
34 | Accepted | 3ms | 4836 KiB | ||||
35 | Accepted | 3ms | 4928 KiB | ||||
36 | Accepted | 4ms | 5196 KiB | ||||
37 | Accepted | 4ms | 5304 KiB | ||||
38 | Accepted | 4ms | 5212 KiB | ||||
39 | Accepted | 4ms | 5012 KiB | ||||
40 | Accepted | 4ms | 5156 KiB | ||||
41 | Accepted | 4ms | 5036 KiB | ||||
42 | Accepted | 4ms | 5128 KiB | ||||
subtask6 | 0/30 | ||||||
43 | Wrong answer | 7ms | 5876 KiB | ||||
44 | Wrong answer | 6ms | 5556 KiB | ||||
45 | Accepted | 4ms | 5004 KiB | ||||
46 | Accepted | 4ms | 5056 KiB | ||||
47 | Accepted | 4ms | 5316 KiB | ||||
48 | Accepted | 4ms | 5436 KiB | ||||
49 | Accepted | 4ms | 5244 KiB | ||||
50 | Accepted | 4ms | 5256 KiB | ||||
51 | Accepted | 4ms | 5260 KiB | ||||
52 | Wrong answer | 8ms | 6084 KiB | ||||
53 | Wrong answer | 6ms | 5736 KiB | ||||
54 | Accepted | 4ms | 5228 KiB | ||||
55 | Accepted | 4ms | 5544 KiB | ||||
56 | Accepted | 4ms | 5472 KiB | ||||
57 | Accepted | 4ms | 5500 KiB | ||||
58 | Accepted | 4ms | 5752 KiB | ||||
59 | Accepted | 4ms | 5596 KiB | ||||
60 | Accepted | 4ms | 5456 KiB |