5033 | 2023-04-10 10:31:03 | horvathabel | Házszámok | cpp17 | Time limit exceeded 0/100 | 298ms | 5624 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
vector<int>darab;
int n;
bool check(int x){
int a=x;
vector<int> valt;
vector<int> db;
db.resize(n,0);
while (x>0){
valt.push_back(x%n);
x/=n;
}
int kell=pow(n,valt.size()-1);
reverse(valt.begin(), valt.end());
for (int i=0; i<n;i++){
db[i]=kell;
}
int cnt=a-(kell-1);
int szamlalo=1;
for (int i=1; i<=valt.size();i++){
int h=0;
db[0]-=szamlalo;
if (i==valt.size()){
h=1;
db[0]+=szamlalo;
}
for (int j=1; j<=cnt;j++){
db[h]++;
if (j%szamlalo==0){
h++;
if (h==n) h=0;
}
}
szamlalo*=n;
}
for (int i=0; i<n;i++){
if (db[i]>darab[i]) return false;
}
return true;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
for (int i=0; i<n;i++){
int x;
cin>>x;
darab.push_back(x);
}
int l=0, r=1e12;
while (l<r){
int m=(l+r)/2;
if (check(m)){
l=m;
}
else{
r=m;
}
cout<<r<<" "<<m<<endl;
}
cout<<r<<endl;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Time limit exceeded | 246ms | 1080 KiB | ||||
2 | Time limit exceeded | 264ms | 1256 KiB | ||||
3 | Time limit exceeded | 263ms | 1556 KiB | ||||
subtask2 | 0/25 | ||||||
4 | Time limit exceeded | 280ms | 2420 KiB | ||||
5 | Time limit exceeded | 264ms | 2636 KiB | ||||
6 | Time limit exceeded | 273ms | 3024 KiB | ||||
7 | Time limit exceeded | 298ms | 3168 KiB | ||||
8 | Time limit exceeded | 256ms | 3240 KiB | ||||
9 | Time limit exceeded | 263ms | 3472 KiB | ||||
10 | Time limit exceeded | 268ms | 2748 KiB | ||||
11 | Time limit exceeded | 264ms | 3716 KiB | ||||
12 | Time limit exceeded | 247ms | 3788 KiB | ||||
13 | Time limit exceeded | 275ms | 3784 KiB | ||||
14 | Time limit exceeded | 263ms | 3824 KiB | ||||
15 | Time limit exceeded | 284ms | 3824 KiB | ||||
16 | Time limit exceeded | 284ms | 3968 KiB | ||||
17 | Time limit exceeded | 250ms | 4208 KiB | ||||
18 | Time limit exceeded | 280ms | 4340 KiB | ||||
19 | Time limit exceeded | 244ms | 4452 KiB | ||||
subtask3 | 0/10 | ||||||
20 | Time limit exceeded | 287ms | 4536 KiB | ||||
21 | Time limit exceeded | 203ms | 4652 KiB | ||||
22 | Time limit exceeded | 259ms | 4664 KiB | ||||
23 | Time limit exceeded | 268ms | 4668 KiB | ||||
24 | Time limit exceeded | 268ms | 4760 KiB | ||||
subtask4 | 0/15 | ||||||
25 | Time limit exceeded | 256ms | 4752 KiB | ||||
26 | Time limit exceeded | 272ms | 4760 KiB | ||||
27 | Time limit exceeded | 273ms | 4756 KiB | ||||
28 | Time limit exceeded | 259ms | 5036 KiB | ||||
29 | Time limit exceeded | 268ms | 5084 KiB | ||||
30 | Time limit exceeded | 256ms | 5092 KiB | ||||
31 | Time limit exceeded | 268ms | 5212 KiB | ||||
32 | Time limit exceeded | 280ms | 5288 KiB | ||||
33 | Time limit exceeded | 263ms | 5424 KiB | ||||
subtask5 | 0/20 | ||||||
34 | Time limit exceeded | 280ms | 5320 KiB | ||||
35 | Time limit exceeded | 275ms | 5208 KiB | ||||
36 | Time limit exceeded | 268ms | 5204 KiB | ||||
37 | Time limit exceeded | 263ms | 5212 KiB | ||||
38 | Time limit exceeded | 275ms | 5212 KiB | ||||
39 | Time limit exceeded | 236ms | 5324 KiB | ||||
40 | Time limit exceeded | 280ms | 5432 KiB | ||||
41 | Time limit exceeded | 244ms | 5432 KiB | ||||
42 | Time limit exceeded | 268ms | 5324 KiB | ||||
subtask6 | 0/30 | ||||||
43 | Time limit exceeded | 239ms | 5340 KiB | ||||
44 | Time limit exceeded | 252ms | 5248 KiB | ||||
45 | Time limit exceeded | 246ms | 4664 KiB | ||||
46 | Time limit exceeded | 275ms | 5352 KiB | ||||
47 | Time limit exceeded | 280ms | 5468 KiB | ||||
48 | Time limit exceeded | 279ms | 5368 KiB | ||||
49 | Time limit exceeded | 263ms | 5368 KiB | ||||
50 | Time limit exceeded | 275ms | 5476 KiB | ||||
51 | Time limit exceeded | 268ms | 5376 KiB | ||||
52 | Time limit exceeded | 272ms | 4688 KiB | ||||
53 | Time limit exceeded | 280ms | 5624 KiB | ||||
54 | Time limit exceeded | 272ms | 5592 KiB | ||||
55 | Time limit exceeded | 270ms | 5404 KiB | ||||
56 | Time limit exceeded | 254ms | 5468 KiB | ||||
57 | Time limit exceeded | 263ms | 5476 KiB | ||||
58 | Time limit exceeded | 268ms | 5480 KiB | ||||
59 | Time limit exceeded | 264ms | 5488 KiB | ||||
60 | Time limit exceeded | 273ms | 5392 KiB |