49882023-04-08 15:40:38TomaSajtHázszámokcpp17Wrong answer 25/1004ms5404 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 = [&](ll 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
1Accepted3ms1812 KiB
2Accepted3ms2228 KiB
3Wrong answer4ms2512 KiB
subtask225/25
4Accepted3ms2344 KiB
5Accepted3ms2456 KiB
6Accepted3ms2668 KiB
7Accepted3ms2660 KiB
8Accepted3ms2912 KiB
9Accepted3ms2888 KiB
10Accepted3ms2980 KiB
11Accepted3ms3084 KiB
12Accepted3ms3196 KiB
13Accepted3ms3460 KiB
14Accepted3ms3352 KiB
15Accepted3ms3616 KiB
16Accepted3ms3484 KiB
17Accepted3ms3500 KiB
18Accepted3ms3496 KiB
19Accepted3ms3492 KiB
subtask30/10
20Wrong answer4ms3852 KiB
21Wrong answer3ms4060 KiB
22Wrong answer3ms4276 KiB
23Accepted3ms4092 KiB
24Wrong answer4ms4360 KiB
subtask40/15
25Wrong answer3ms4364 KiB
26Wrong answer4ms4208 KiB
27Wrong answer4ms4488 KiB
28Wrong answer3ms4556 KiB
29Wrong answer4ms4564 KiB
30Accepted3ms4324 KiB
31Wrong answer4ms4716 KiB
32Wrong answer4ms4724 KiB
33Wrong answer4ms4824 KiB
subtask50/20
34Accepted3ms4536 KiB
35Accepted3ms4528 KiB
36Wrong answer4ms4804 KiB
37Wrong answer4ms4812 KiB
38Wrong answer4ms4808 KiB
39Wrong answer4ms4804 KiB
40Wrong answer4ms4812 KiB
41Wrong answer4ms4812 KiB
42Wrong answer4ms4936 KiB
subtask60/30
43Wrong answer3ms4996 KiB
44Wrong answer3ms4848 KiB
45Wrong answer3ms4996 KiB
46Wrong answer3ms4984 KiB
47Wrong answer3ms5116 KiB
48Wrong answer3ms5204 KiB
49Wrong answer4ms5404 KiB
50Wrong answer4ms5264 KiB
51Wrong answer4ms5252 KiB
52Accepted3ms4964 KiB
53Wrong answer4ms5076 KiB
54Wrong answer4ms5224 KiB
55Wrong answer3ms5212 KiB
56Wrong answer3ms5352 KiB
57Wrong answer3ms5360 KiB
58Wrong answer4ms5396 KiB
59Wrong answer4ms5244 KiB
60Wrong answer4ms5352 KiB