20862022-12-16 22:28:45TomaSajtHázszámokcpp17Wrong answer 0/1003ms4952 KiB
// 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1760 KiB
2Accepted2ms1932 KiB
3Wrong answer2ms2132 KiB
subtask20/25
4Wrong answer2ms2336 KiB
5Wrong answer2ms2540 KiB
6Wrong answer2ms2740 KiB
7Wrong answer2ms2948 KiB
8Wrong answer2ms3024 KiB
9Accepted2ms3152 KiB
10Wrong answer2ms3232 KiB
11Wrong answer2ms3360 KiB
12Wrong answer2ms3436 KiB
13Wrong answer2ms3428 KiB
14Wrong answer2ms3436 KiB
15Wrong answer2ms3432 KiB
16Wrong answer2ms3432 KiB
17Wrong answer2ms3556 KiB
18Wrong answer2ms3912 KiB
19Wrong answer2ms3652 KiB
subtask30/10
20Wrong answer2ms3744 KiB
21Wrong answer2ms3872 KiB
22Wrong answer2ms3932 KiB
23Wrong answer2ms3828 KiB
24Wrong answer2ms3832 KiB
subtask40/15
25Wrong answer2ms3832 KiB
26Wrong answer2ms3832 KiB
27Wrong answer2ms3832 KiB
28Wrong answer2ms3832 KiB
29Wrong answer2ms3828 KiB
30Wrong answer2ms3836 KiB
31Wrong answer2ms3960 KiB
32Wrong answer2ms4032 KiB
33Wrong answer2ms4040 KiB
subtask50/20
34Wrong answer2ms4160 KiB
35Wrong answer2ms4264 KiB
36Wrong answer2ms4264 KiB
37Wrong answer2ms4268 KiB
38Wrong answer2ms4340 KiB
39Wrong answer2ms4340 KiB
40Wrong answer2ms4364 KiB
41Wrong answer2ms4448 KiB
42Wrong answer2ms4540 KiB
subtask60/30
43Wrong answer2ms4444 KiB
44Wrong answer2ms4672 KiB
45Wrong answer2ms4772 KiB
46Wrong answer2ms4772 KiB
47Wrong answer2ms4748 KiB
48Wrong answer2ms4748 KiB
49Wrong answer2ms4848 KiB
50Wrong answer2ms4648 KiB
51Wrong answer2ms4792 KiB
52Wrong answer2ms4904 KiB
53Wrong answer2ms4900 KiB
54Wrong answer2ms4900 KiB
55Wrong answer2ms4900 KiB
56Wrong answer2ms4792 KiB
57Wrong answer2ms4792 KiB
58Wrong answer2ms4952 KiB
59Wrong answer2ms4808 KiB
60Wrong answer2ms4812 KiB