49862023-04-08 15:38:36TomaSajtHázszámokcpp17Wrong answer 25/1003ms5424 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int base;

map<pair<int, 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({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[make_pair(n, d)] = res;
}

int main() {
  cin >> base;
  vector<ll> budget(base);
  for (auto &b : budget)
    cin >> b;
  auto is_enough = [&](int 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 = 20; i >= 0; i--) {
    ll next = curr + (1ll << i);
    if (is_enough(next)) {
      curr = next;
    }
  }
  cout << curr;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1684 KiB
2Accepted3ms1880 KiB
3Wrong answer3ms2512 KiB
subtask225/25
4Accepted3ms2428 KiB
5Accepted3ms2528 KiB
6Accepted3ms2740 KiB
7Accepted3ms2956 KiB
8Accepted3ms3048 KiB
9Accepted3ms3316 KiB
10Accepted3ms3508 KiB
11Accepted3ms3676 KiB
12Accepted3ms3856 KiB
13Accepted3ms3732 KiB
14Accepted3ms3724 KiB
15Accepted3ms3856 KiB
16Accepted3ms3860 KiB
17Accepted3ms4000 KiB
18Accepted3ms4100 KiB
19Accepted3ms4180 KiB
subtask30/10
20Wrong answer3ms4224 KiB
21Wrong answer3ms4224 KiB
22Wrong answer3ms4224 KiB
23Accepted3ms4208 KiB
24Wrong answer3ms4432 KiB
subtask40/15
25Wrong answer3ms4604 KiB
26Wrong answer3ms4496 KiB
27Wrong answer3ms4656 KiB
28Wrong answer3ms4592 KiB
29Wrong answer3ms4596 KiB
30Accepted3ms4716 KiB
31Wrong answer3ms4976 KiB
32Wrong answer3ms5068 KiB
33Wrong answer3ms5188 KiB
subtask50/20
34Accepted3ms4940 KiB
35Accepted3ms4984 KiB
36Wrong answer3ms5144 KiB
37Wrong answer3ms5068 KiB
38Wrong answer3ms5164 KiB
39Wrong answer3ms5168 KiB
40Wrong answer3ms5172 KiB
41Wrong answer3ms5168 KiB
42Wrong answer3ms5324 KiB
subtask60/30
43Wrong answer3ms5212 KiB
44Wrong answer3ms5192 KiB
45Wrong answer3ms5424 KiB
46Wrong answer3ms5264 KiB
47Wrong answer3ms5272 KiB
48Wrong answer3ms5408 KiB
49Wrong answer3ms5324 KiB
50Wrong answer3ms5164 KiB
51Wrong answer3ms5172 KiB
52Accepted3ms5132 KiB
53Wrong answer3ms5328 KiB
54Wrong answer3ms5300 KiB
55Wrong answer3ms5160 KiB
56Wrong answer3ms5164 KiB
57Wrong answer3ms5176 KiB
58Wrong answer3ms5188 KiB
59Wrong answer3ms5180 KiB
60Wrong answer3ms5316 KiB