5242 | 2023-04-23 17:09:19 | ZsofiaKeresztely | Házszámok | cpp14 | Wrong answer 0/100 | 3ms | 5392 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);
int power = 1;
for (int i=0; i<n.size(); i++){
req[0] += power * (m / (power * k));
if (n[i] == 0) req[0] -= power;
if (req[0] > lim[0]) return 0;
for (int j=1; j<n[i]; j++){
req[j] += power * (m / (power * k) + 1);
if (req[j] > lim[j]) return 0;
}
for (int j=n[i]; j<k; j++){
req[j] += power * (m / (power * k));
if (req[j] > lim[j]) return 0;
}
power *= 3;
}
return true;
}
int main()
{
cin >> k;
lim.resize(k);
for (ll &x : lim){
cin >> x;
}
ll l = 2, r = 1e14;
while (l + 1 < r){
ll m = (l + r) / 2;
if (ok(m, convert(m))){
l = m;
}
else{
r = m;
}
}
cout << l - 1;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1808 KiB | ||||
2 | Wrong answer | 3ms | 2000 KiB | ||||
3 | Wrong answer | 3ms | 2216 KiB | ||||
subtask2 | 0/25 | ||||||
4 | Wrong answer | 3ms | 2428 KiB | ||||
5 | Wrong answer | 3ms | 2792 KiB | ||||
6 | Wrong answer | 3ms | 2736 KiB | ||||
7 | Wrong answer | 3ms | 2968 KiB | ||||
8 | Wrong answer | 3ms | 3176 KiB | ||||
9 | Wrong answer | 3ms | 3428 KiB | ||||
10 | Wrong answer | 3ms | 3600 KiB | ||||
11 | Wrong answer | 3ms | 3692 KiB | ||||
12 | Wrong answer | 3ms | 3692 KiB | ||||
13 | Wrong answer | 3ms | 3820 KiB | ||||
14 | Wrong answer | 3ms | 4028 KiB | ||||
15 | Wrong answer | 3ms | 4164 KiB | ||||
16 | Wrong answer | 2ms | 4244 KiB | ||||
17 | Wrong answer | 3ms | 4324 KiB | ||||
18 | Wrong answer | 3ms | 4324 KiB | ||||
19 | Wrong answer | 2ms | 4320 KiB | ||||
subtask3 | 0/10 | ||||||
20 | Wrong answer | 3ms | 4440 KiB | ||||
21 | Wrong answer | 3ms | 4436 KiB | ||||
22 | Wrong answer | 3ms | 4432 KiB | ||||
23 | Wrong answer | 3ms | 4460 KiB | ||||
24 | Wrong answer | 3ms | 4536 KiB | ||||
subtask4 | 0/15 | ||||||
25 | Wrong answer | 3ms | 4424 KiB | ||||
26 | Wrong answer | 2ms | 4428 KiB | ||||
27 | Wrong answer | 3ms | 4552 KiB | ||||
28 | Wrong answer | 2ms | 4548 KiB | ||||
29 | Wrong answer | 3ms | 4800 KiB | ||||
30 | Wrong answer | 2ms | 4892 KiB | ||||
31 | Wrong answer | 2ms | 4976 KiB | ||||
32 | Wrong answer | 2ms | 4944 KiB | ||||
33 | Wrong answer | 2ms | 4944 KiB | ||||
subtask5 | 0/20 | ||||||
34 | Wrong answer | 3ms | 4944 KiB | ||||
35 | Wrong answer | 3ms | 4944 KiB | ||||
36 | Wrong answer | 3ms | 4948 KiB | ||||
37 | Wrong answer | 3ms | 5056 KiB | ||||
38 | Wrong answer | 2ms | 5060 KiB | ||||
39 | Wrong answer | 2ms | 5176 KiB | ||||
40 | Wrong answer | 3ms | 5056 KiB | ||||
41 | Wrong answer | 2ms | 5172 KiB | ||||
42 | Wrong answer | 2ms | 5288 KiB | ||||
subtask6 | 0/30 | ||||||
43 | Wrong answer | 3ms | 5168 KiB | ||||
44 | Wrong answer | 3ms | 5060 KiB | ||||
45 | Wrong answer | 3ms | 5176 KiB | ||||
46 | Wrong answer | 2ms | 4944 KiB | ||||
47 | Wrong answer | 3ms | 5060 KiB | ||||
48 | Wrong answer | 3ms | 5060 KiB | ||||
49 | Wrong answer | 3ms | 5056 KiB | ||||
50 | Wrong answer | 3ms | 5184 KiB | ||||
51 | Wrong answer | 2ms | 5268 KiB | ||||
52 | Wrong answer | 2ms | 5268 KiB | ||||
53 | Wrong answer | 2ms | 5388 KiB | ||||
54 | Wrong answer | 2ms | 5272 KiB | ||||
55 | Wrong answer | 2ms | 5392 KiB | ||||
56 | Wrong answer | 2ms | 5272 KiB | ||||
57 | Wrong answer | 3ms | 5152 KiB | ||||
58 | Wrong answer | 2ms | 5160 KiB | ||||
59 | Wrong answer | 2ms | 5156 KiB | ||||
60 | Wrong answer | 2ms | 5272 KiB |