5245 | 2023-04-23 18:46:34 | ZsofiaKeresztely | Házszámok | cpp14 | Accepted 100/100 | 3ms | 4792 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> lim;
int k;
vector<int> convert(ll n){
vector<int> r;
while (n){
r.push_back(n % k);
n /= k;
}
return r;
}
bool ok(ll m, vector<int> n){
vector<ll> req(k, 0);
ll power = 1;
for (int i=0; i<n.size(); i++){
ll quo = m / (power * k);
for (int j=0; j<n[i]; j++){
req[j] += power * (quo + 1);
}
req[n[i]] += m % power + 1;
for (int j=n[i]; j<k; j++){
req[j] += power * quo;
}
req[0] -= power;
for (int j=0; j<k; j++){
if (req[j] > lim[j]) return 0;
}
power *= k;
}
return 1;
}
int main()
{
cin >> k;
lim.resize(k);
for (ll &x : lim){
cin >> x;
}
ll l = 1, r = 1e13;
while (l + 1 < r){
ll m = (l + r) / 2;
if (ok(m, convert(m))){
l = m;
}
else{
r = m;
}
}
cout << l;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1684 KiB | ||||
2 | Accepted | 3ms | 1924 KiB | ||||
3 | Accepted | 3ms | 2012 KiB | ||||
subtask2 | 25/25 | ||||||
4 | Accepted | 3ms | 2152 KiB | ||||
5 | Accepted | 3ms | 2512 KiB | ||||
6 | Accepted | 3ms | 2596 KiB | ||||
7 | Accepted | 3ms | 2712 KiB | ||||
8 | Accepted | 3ms | 2776 KiB | ||||
9 | Accepted | 2ms | 2972 KiB | ||||
10 | Accepted | 3ms | 3216 KiB | ||||
11 | Accepted | 3ms | 3300 KiB | ||||
12 | Accepted | 3ms | 3396 KiB | ||||
13 | Accepted | 3ms | 3508 KiB | ||||
14 | Accepted | 3ms | 3508 KiB | ||||
15 | Accepted | 3ms | 3484 KiB | ||||
16 | Accepted | 3ms | 3716 KiB | ||||
17 | Accepted | 3ms | 3688 KiB | ||||
18 | Accepted | 3ms | 3824 KiB | ||||
19 | Accepted | 3ms | 4064 KiB | ||||
subtask3 | 10/10 | ||||||
20 | Accepted | 3ms | 4152 KiB | ||||
21 | Accepted | 3ms | 4152 KiB | ||||
22 | Accepted | 3ms | 4264 KiB | ||||
23 | Accepted | 3ms | 4120 KiB | ||||
24 | Accepted | 3ms | 4144 KiB | ||||
subtask4 | 15/15 | ||||||
25 | Accepted | 3ms | 4244 KiB | ||||
26 | Accepted | 3ms | 4348 KiB | ||||
27 | Accepted | 3ms | 4240 KiB | ||||
28 | Accepted | 3ms | 4232 KiB | ||||
29 | Accepted | 3ms | 4124 KiB | ||||
30 | Accepted | 3ms | 4124 KiB | ||||
31 | Accepted | 3ms | 4280 KiB | ||||
32 | Accepted | 3ms | 4268 KiB | ||||
33 | Accepted | 3ms | 4388 KiB | ||||
subtask5 | 20/20 | ||||||
34 | Accepted | 3ms | 4268 KiB | ||||
35 | Accepted | 3ms | 4520 KiB | ||||
36 | Accepted | 3ms | 4516 KiB | ||||
37 | Accepted | 3ms | 4488 KiB | ||||
38 | Accepted | 3ms | 4484 KiB | ||||
39 | Accepted | 3ms | 4508 KiB | ||||
40 | Accepted | 3ms | 4496 KiB | ||||
41 | Accepted | 3ms | 4484 KiB | ||||
42 | Accepted | 3ms | 4480 KiB | ||||
subtask6 | 30/30 | ||||||
43 | Accepted | 3ms | 4488 KiB | ||||
44 | Accepted | 3ms | 4484 KiB | ||||
45 | Accepted | 3ms | 4480 KiB | ||||
46 | Accepted | 3ms | 4604 KiB | ||||
47 | Accepted | 3ms | 4604 KiB | ||||
48 | Accepted | 3ms | 4600 KiB | ||||
49 | Accepted | 3ms | 4600 KiB | ||||
50 | Accepted | 3ms | 4480 KiB | ||||
51 | Accepted | 3ms | 4480 KiB | ||||
52 | Accepted | 3ms | 4484 KiB | ||||
53 | Accepted | 3ms | 4512 KiB | ||||
54 | Accepted | 3ms | 4484 KiB | ||||
55 | Accepted | 3ms | 4600 KiB | ||||
56 | Accepted | 3ms | 4548 KiB | ||||
57 | Accepted | 3ms | 4660 KiB | ||||
58 | Accepted | 3ms | 4792 KiB | ||||
59 | Accepted | 3ms | 4688 KiB | ||||
60 | Accepted | 3ms | 4712 KiB |