49872023-04-08 15:39:24TomaSajtHázszámokcpp17Wrong answer 25/1004ms5348 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 = 28; i >= 0; i--) {
    ll next = curr + (1ll << i);
    if (is_enough(next)) {
      curr = next;
    }
  }
  cout << curr;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1816 KiB
2Accepted3ms2172 KiB
3Wrong answer4ms2476 KiB
subtask225/25
4Accepted3ms2448 KiB
5Accepted3ms2664 KiB
6Accepted3ms2880 KiB
7Accepted3ms3108 KiB
8Accepted3ms3200 KiB
9Accepted3ms3456 KiB
10Accepted3ms3500 KiB
11Accepted3ms3736 KiB
12Accepted3ms3680 KiB
13Accepted3ms4076 KiB
14Accepted3ms4060 KiB
15Accepted3ms4276 KiB
16Accepted3ms4332 KiB
17Accepted3ms4348 KiB
18Accepted3ms4408 KiB
19Accepted3ms4500 KiB
subtask30/10
20Wrong answer3ms4736 KiB
21Wrong answer3ms4736 KiB
22Wrong answer3ms4740 KiB
23Accepted3ms4380 KiB
24Wrong answer3ms4644 KiB
subtask40/15
25Wrong answer4ms4696 KiB
26Wrong answer3ms4648 KiB
27Wrong answer4ms4928 KiB
28Wrong answer3ms4912 KiB
29Wrong answer3ms5084 KiB
30Accepted3ms4844 KiB
31Wrong answer4ms5124 KiB
32Wrong answer4ms5176 KiB
33Wrong answer4ms5112 KiB
subtask50/20
34Accepted3ms4916 KiB
35Accepted3ms4920 KiB
36Wrong answer4ms5260 KiB
37Wrong answer4ms5112 KiB
38Wrong answer4ms5112 KiB
39Wrong answer4ms5332 KiB
40Wrong answer4ms5200 KiB
41Wrong answer4ms5108 KiB
42Wrong answer4ms5108 KiB
subtask60/30
43Wrong answer3ms5092 KiB
44Wrong answer3ms5036 KiB
45Wrong answer3ms5092 KiB
46Wrong answer3ms5188 KiB
47Wrong answer4ms5216 KiB
48Wrong answer4ms5332 KiB
49Wrong answer4ms5348 KiB
50Wrong answer4ms5176 KiB
51Wrong answer4ms5184 KiB
52Accepted3ms4904 KiB
53Wrong answer3ms5008 KiB
54Wrong answer4ms5160 KiB
55Wrong answer3ms5144 KiB
56Wrong answer4ms5152 KiB
57Wrong answer4ms5156 KiB
58Wrong answer4ms5328 KiB
59Wrong answer4ms5264 KiB
60Wrong answer4ms5328 KiB