39242023-03-05 17:54:00zsomborHázszámokcpp17Wrong answer 25/1003ms5176 KiB
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

ll k, n = 0;
vector <ll> h(51, 1);
vector <ll> CNT(10, 0);
vector <ll> cnt(10, 0);
vector <ll> v(51, 0);

bool check(ll x) {
    fill(cnt.begin(), cnt.end(), 0);
    fill(v.begin(), v.end(), 0);
    for (int i = 1; i <= n; i++) {
        if (x < h[i]-1) {
            cnt[0] += ((x + 1) % h[i - 1]) * i;
            break;
        }
        cnt[0] += (k - 1) * h[i - 1] * i;
    }
    for (int i = n; i >= 0; i--) {
        v[i] = x / h[i];
        x %= h[i];
        if (v[i]) cnt[v[i]] += x + 1;
        for (int j = 1; j < v[i]; j++) cnt[j] += h[i];
        for (int j = 1; j < k; j++) cnt[j] += h[i] * i / k * v[i];
    }
    for (int i = 1; i < k; i++) cnt[0] -= cnt[i];
    for (int i = 0; i < k; i++) if (cnt[i] > CNT[i]) return false;
    return true;
}

int main()
{
    cin >> k;
    while (h[n] < 1e15) { n++; h[n] = k * h[n - 1]; }
    for (int i = 0; i < k; i++) cin >> CNT[i];
    ll l = 0, r = 1e13, m;
    while (r - l > 1) {
        m = (l + r) / 2;
        (check(m) ? l = m : r = m);
    }
    cout << l;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1876 KiB
2Accepted3ms2084 KiB
3Accepted3ms2296 KiB
subtask20/25
4Accepted3ms2660 KiB
5Accepted3ms2596 KiB
6Accepted3ms2596 KiB
7Accepted3ms2792 KiB
8Accepted3ms2876 KiB
9Accepted3ms3004 KiB
10Accepted3ms3120 KiB
11Accepted3ms3244 KiB
12Accepted3ms3464 KiB
13Accepted3ms3568 KiB
14Accepted3ms3668 KiB
15Wrong answer3ms3752 KiB
16Accepted3ms3844 KiB
17Accepted3ms3980 KiB
18Accepted2ms4060 KiB
19Accepted3ms4100 KiB
subtask310/10
20Accepted2ms4176 KiB
21Accepted3ms4304 KiB
22Accepted3ms4388 KiB
23Accepted3ms4504 KiB
24Accepted3ms4664 KiB
subtask415/15
25Accepted3ms4528 KiB
26Accepted3ms4532 KiB
27Accepted3ms4592 KiB
28Accepted2ms4588 KiB
29Accepted3ms4844 KiB
30Accepted3ms4848 KiB
31Accepted2ms4864 KiB
32Accepted3ms4864 KiB
33Accepted2ms4860 KiB
subtask50/20
34Accepted3ms4824 KiB
35Accepted3ms4936 KiB
36Wrong answer3ms5064 KiB
37Accepted3ms5056 KiB
38Accepted3ms5060 KiB
39Accepted3ms5176 KiB
40Accepted3ms5064 KiB
41Accepted3ms4940 KiB
42Accepted3ms5076 KiB
subtask60/30
43Accepted3ms5064 KiB
44Accepted3ms5036 KiB
45Accepted3ms5032 KiB
46Accepted3ms5064 KiB
47Accepted3ms5156 KiB
48Wrong answer3ms5176 KiB
49Accepted3ms5152 KiB
50Accepted3ms5144 KiB
51Accepted3ms5040 KiB
52Accepted3ms5036 KiB
53Accepted3ms5152 KiB
54Accepted3ms5036 KiB
55Accepted3ms5032 KiB
56Accepted3ms5064 KiB
57Accepted3ms5036 KiB
58Accepted3ms5148 KiB
59Accepted2ms5148 KiB
60Accepted3ms5144 KiB