49852023-04-08 15:33:49TomaSajtHázszámokcpp17Wrong answer 25/100300ms4916 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int base;

// 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;
  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)
    return res + 1;
  return 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
1Accepted32ms1732 KiB
2Accepted3ms1856 KiB
3Wrong answer3ms2096 KiB
subtask225/25
4Accepted32ms2344 KiB
5Accepted35ms2588 KiB
6Accepted34ms2768 KiB
7Accepted3ms2924 KiB
8Accepted3ms3136 KiB
9Accepted3ms3352 KiB
10Accepted34ms3556 KiB
11Accepted3ms3812 KiB
12Accepted3ms3888 KiB
13Accepted3ms4020 KiB
14Accepted3ms4196 KiB
15Accepted3ms4308 KiB
16Accepted3ms4364 KiB
17Accepted3ms4240 KiB
18Accepted2ms4248 KiB
19Accepted3ms4480 KiB
subtask30/10
20Time limit exceeded261ms4432 KiB
21Time limit exceeded263ms4452 KiB
22Time limit exceeded268ms4328 KiB
23Accepted30ms4456 KiB
24Time limit exceeded300ms4564 KiB
subtask40/15
25Time limit exceeded264ms4536 KiB
26Wrong answer14ms4668 KiB
27Wrong answer4ms4668 KiB
28Wrong answer4ms4700 KiB
29Wrong answer3ms4680 KiB
30Accepted3ms4680 KiB
31Wrong answer3ms4672 KiB
32Wrong answer3ms4672 KiB
33Wrong answer3ms4796 KiB
subtask50/20
34Accepted3ms4796 KiB
35Accepted2ms4816 KiB
36Wrong answer3ms4788 KiB
37Wrong answer3ms4796 KiB
38Wrong answer3ms4916 KiB
39Wrong answer3ms4800 KiB
40Wrong answer3ms4796 KiB
41Wrong answer3ms4676 KiB
42Wrong answer3ms4788 KiB
subtask60/30
43Time limit exceeded300ms4764 KiB
44Wrong answer14ms4816 KiB
45Wrong answer4ms4792 KiB
46Wrong answer4ms4792 KiB
47Wrong answer3ms4788 KiB
48Wrong answer3ms4672 KiB
49Wrong answer3ms4672 KiB
50Wrong answer3ms4676 KiB
51Wrong answer3ms4672 KiB
52Accepted32ms4672 KiB
53Wrong answer14ms4796 KiB
54Wrong answer4ms4676 KiB
55Wrong answer4ms4788 KiB
56Wrong answer3ms4788 KiB
57Wrong answer3ms4676 KiB
58Wrong answer3ms4672 KiB
59Wrong answer3ms4676 KiB
60Wrong answer3ms4788 KiB