39182023-03-05 15:32:39zsomborHázszámokcpp17Wrong answer 0/1003ms5004 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 = 6, m;
    while (r - l > 1) {
        m = (l + r) / 2;
        (check(m) ? l = m : r = m);
    }
    cout << l;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1872 KiB
2Wrong answer2ms2128 KiB
3Wrong answer2ms2336 KiB
subtask20/25
4Wrong answer2ms2488 KiB
5Wrong answer3ms2700 KiB
6Wrong answer3ms2912 KiB
7Wrong answer3ms3128 KiB
8Wrong answer2ms3244 KiB
9Wrong answer2ms3492 KiB
10Wrong answer2ms3716 KiB
11Wrong answer2ms3740 KiB
12Wrong answer2ms3752 KiB
13Wrong answer2ms3876 KiB
14Wrong answer2ms3748 KiB
15Wrong answer2ms3756 KiB
16Wrong answer2ms3756 KiB
17Wrong answer2ms3756 KiB
18Wrong answer3ms3752 KiB
19Wrong answer2ms3752 KiB
subtask30/10
20Wrong answer2ms3752 KiB
21Wrong answer3ms3868 KiB
22Wrong answer3ms3876 KiB
23Accepted3ms4092 KiB
24Wrong answer2ms4144 KiB
subtask40/15
25Wrong answer2ms4140 KiB
26Wrong answer3ms4272 KiB
27Wrong answer3ms4480 KiB
28Wrong answer2ms4564 KiB
29Wrong answer3ms4564 KiB
30Wrong answer3ms4568 KiB
31Wrong answer2ms4572 KiB
32Wrong answer3ms4580 KiB
33Wrong answer3ms4708 KiB
subtask50/20
34Wrong answer2ms4788 KiB
35Wrong answer3ms4784 KiB
36Wrong answer2ms4792 KiB
37Wrong answer2ms4784 KiB
38Wrong answer2ms4792 KiB
39Wrong answer3ms4788 KiB
40Wrong answer3ms4788 KiB
41Wrong answer2ms4788 KiB
42Wrong answer2ms4788 KiB
subtask60/30
43Wrong answer2ms4784 KiB
44Wrong answer2ms4784 KiB
45Wrong answer2ms4788 KiB
46Wrong answer2ms4816 KiB
47Wrong answer3ms4812 KiB
48Wrong answer2ms4804 KiB
49Wrong answer3ms4940 KiB
50Wrong answer3ms4948 KiB
51Wrong answer3ms4916 KiB
52Accepted3ms4940 KiB
53Wrong answer3ms5004 KiB
54Wrong answer3ms4900 KiB
55Wrong answer3ms4896 KiB
56Wrong answer3ms4892 KiB
57Wrong answer3ms4900 KiB
58Wrong answer3ms4896 KiB
59Wrong answer2ms4896 KiB
60Wrong answer3ms4896 KiB