// ez valami régi kód, nem tudom, működik-e
#include <bits/stdc++.h>
using namespace std;
#define speed ios::sync_with_stdio(0);cin.tie(0)
int k;
vector<int> budget;
vector<int> digits;
map<int, long long> mem;
long long pn(int e) {
if (mem[e]) return mem[e];
long long h = pn(e / 2);
return mem[e] = (e % 2 == 0 ? h * h : h * h * k);
}
long long f(int d) {
return (d + 1) * pn(d);
}
long long g(int d) {
if (d == 0) return 0;
return (k - 1) * f(d - 1) + g(d - 1);
}
int calcDig(int i) {
int a = f(i - 1);
for (int j = 1; j < k; j++) {
for (int l = 0; l < k; l++) {
budget[l] -= a;
}
bool o = false;
for (int l = 0; l < k; l++) {
if (budget[l] < 0) {
o = true;
break;
}
}
if (!o) continue;
for (int l = 0; l < k; l++) {
budget[l] += a;
}
return j - 1;
}
return k - 1;
}
int main() {
speed;
mem[0] = 1;
cin >> k;
budget.resize(k);
for (int& a : budget)
cin >> a;
int dig;
for (int i = 0;; i++) {
for (int j = 0; j < k; j++) {
int c = j == 0 ? g(i) : f(i);
if (budget[j] < c) {
dig = i;
goto after;
}
}
}
after:
digits.resize(dig + 1);
for (int i = dig; i >= 0; i--) {
digits[i] = calcDig(i);
}
int res = 0;
for (int i = dig; i >= 0; i--) {
res *= k;
res += digits[i];
}
cout << res - 1 << endl;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1760 KiB | ||||
2 | Accepted | 2ms | 1932 KiB | ||||
3 | Wrong answer | 2ms | 2132 KiB | ||||
subtask2 | 0/25 | ||||||
4 | Wrong answer | 2ms | 2336 KiB | ||||
5 | Wrong answer | 2ms | 2540 KiB | ||||
6 | Wrong answer | 2ms | 2740 KiB | ||||
7 | Wrong answer | 2ms | 2948 KiB | ||||
8 | Wrong answer | 2ms | 3024 KiB | ||||
9 | Accepted | 2ms | 3152 KiB | ||||
10 | Wrong answer | 2ms | 3232 KiB | ||||
11 | Wrong answer | 2ms | 3360 KiB | ||||
12 | Wrong answer | 2ms | 3436 KiB | ||||
13 | Wrong answer | 2ms | 3428 KiB | ||||
14 | Wrong answer | 2ms | 3436 KiB | ||||
15 | Wrong answer | 2ms | 3432 KiB | ||||
16 | Wrong answer | 2ms | 3432 KiB | ||||
17 | Wrong answer | 2ms | 3556 KiB | ||||
18 | Wrong answer | 2ms | 3912 KiB | ||||
19 | Wrong answer | 2ms | 3652 KiB | ||||
subtask3 | 0/10 | ||||||
20 | Wrong answer | 2ms | 3744 KiB | ||||
21 | Wrong answer | 2ms | 3872 KiB | ||||
22 | Wrong answer | 2ms | 3932 KiB | ||||
23 | Wrong answer | 2ms | 3828 KiB | ||||
24 | Wrong answer | 2ms | 3832 KiB | ||||
subtask4 | 0/15 | ||||||
25 | Wrong answer | 2ms | 3832 KiB | ||||
26 | Wrong answer | 2ms | 3832 KiB | ||||
27 | Wrong answer | 2ms | 3832 KiB | ||||
28 | Wrong answer | 2ms | 3832 KiB | ||||
29 | Wrong answer | 2ms | 3828 KiB | ||||
30 | Wrong answer | 2ms | 3836 KiB | ||||
31 | Wrong answer | 2ms | 3960 KiB | ||||
32 | Wrong answer | 2ms | 4032 KiB | ||||
33 | Wrong answer | 2ms | 4040 KiB | ||||
subtask5 | 0/20 | ||||||
34 | Wrong answer | 2ms | 4160 KiB | ||||
35 | Wrong answer | 2ms | 4264 KiB | ||||
36 | Wrong answer | 2ms | 4264 KiB | ||||
37 | Wrong answer | 2ms | 4268 KiB | ||||
38 | Wrong answer | 2ms | 4340 KiB | ||||
39 | Wrong answer | 2ms | 4340 KiB | ||||
40 | Wrong answer | 2ms | 4364 KiB | ||||
41 | Wrong answer | 2ms | 4448 KiB | ||||
42 | Wrong answer | 2ms | 4540 KiB | ||||
subtask6 | 0/30 | ||||||
43 | Wrong answer | 2ms | 4444 KiB | ||||
44 | Wrong answer | 2ms | 4672 KiB | ||||
45 | Wrong answer | 2ms | 4772 KiB | ||||
46 | Wrong answer | 2ms | 4772 KiB | ||||
47 | Wrong answer | 2ms | 4748 KiB | ||||
48 | Wrong answer | 2ms | 4748 KiB | ||||
49 | Wrong answer | 2ms | 4848 KiB | ||||
50 | Wrong answer | 2ms | 4648 KiB | ||||
51 | Wrong answer | 2ms | 4792 KiB | ||||
52 | Wrong answer | 2ms | 4904 KiB | ||||
53 | Wrong answer | 2ms | 4900 KiB | ||||
54 | Wrong answer | 2ms | 4900 KiB | ||||
55 | Wrong answer | 2ms | 4900 KiB | ||||
56 | Wrong answer | 2ms | 4792 KiB | ||||
57 | Wrong answer | 2ms | 4792 KiB | ||||
58 | Wrong answer | 2ms | 4952 KiB | ||||
59 | Wrong answer | 2ms | 4808 KiB | ||||
60 | Wrong answer | 2ms | 4812 KiB |