#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define el '\n'
#define ld long double
const int maxn=1e5+1,nn=1e7+1;
int a[maxn],n,m,q,p,oo,ans,k,f[nn],ut[nn];
int t;
bool ok;
void check(){
t=1;
ok=0;
for(int i=0;i<m;++i){
k=t*a[i];
if(t*a[i]<t || t*a[i]>oo || k/a[i]!=t){
ok=1;
return;
}
t=t*a[i];
}
}
int sol(int z){
if(f[z]>=0) return f[z];
f[z]=sol(z-ut[z])+1;
return f[z];
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin >> m >> q;
for(int i=0;i<m;++i) cin >> a[i];
sort(a+0,a+m);
for(int i=0;i<m;++i){
for(int j=a[i]-1;j<nn;j+=a[i]){
ut[ j ]=max(a[i]-1,ut[j]);
}
}
int ma;
for(int i=1;i<a[m-1];++i) ut[i]=i;
for(int z=a[m-1];z<nn;++z){
if(ut[z]==0){
ma=0;
for(int i=0;i<m && ma<a[i];++i) if(z%a[i]>ma) ma=z%a[i];
ut[z]=ma;
}
}
memset(f,-1,sizeof f);
f[0]=0;
oo=1e7;
check();
while(q--){
cin >> n;
if(ok){
cout << sol(n);
} else {
if(n>=t){
cout << "oo";
} else {
cout << sol(n);
}
}
cout << el;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
230 ms |
78532 KB |
Output isn't correct |
2 |
Incorrect |
839 ms |
78476 KB |
Output isn't correct |
3 |
Incorrect |
198 ms |
78484 KB |
Output isn't correct |
4 |
Execution timed out |
1090 ms |
39388 KB |
Time limit exceeded |
5 |
Incorrect |
604 ms |
78532 KB |
Output isn't correct |
6 |
Incorrect |
230 ms |
78504 KB |
Output isn't correct |
7 |
Incorrect |
196 ms |
78532 KB |
Output isn't correct |
8 |
Incorrect |
172 ms |
78472 KB |
Output isn't correct |
9 |
Incorrect |
213 ms |
78476 KB |
Output isn't correct |
10 |
Incorrect |
316 ms |
78532 KB |
Output isn't correct |
11 |
Incorrect |
512 ms |
78480 KB |
Output isn't correct |
12 |
Execution timed out |
1096 ms |
39372 KB |
Time limit exceeded |
13 |
Execution timed out |
1097 ms |
39372 KB |
Time limit exceeded |
14 |
Execution timed out |
1077 ms |
39372 KB |
Time limit exceeded |
15 |
Incorrect |
702 ms |
78452 KB |
Output isn't correct |
16 |
Incorrect |
820 ms |
78468 KB |
Output isn't correct |
17 |
Execution timed out |
1091 ms |
39372 KB |
Time limit exceeded |
18 |
Execution timed out |
1087 ms |
39384 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1096 ms |
39500 KB |
Time limit exceeded |
2 |
Execution timed out |
1094 ms |
39756 KB |
Time limit exceeded |
3 |
Execution timed out |
1054 ms |
39628 KB |
Time limit exceeded |
4 |
Execution timed out |
1073 ms |
39372 KB |
Time limit exceeded |
5 |
Execution timed out |
1095 ms |
39696 KB |
Time limit exceeded |
6 |
Execution timed out |
1093 ms |
39364 KB |
Time limit exceeded |
7 |
Execution timed out |
1091 ms |
39500 KB |
Time limit exceeded |
8 |
Execution timed out |
1092 ms |
39372 KB |
Time limit exceeded |
9 |
Execution timed out |
1083 ms |
39628 KB |
Time limit exceeded |
10 |
Execution timed out |
1085 ms |
39748 KB |
Time limit exceeded |
11 |
Execution timed out |
1093 ms |
39508 KB |
Time limit exceeded |
12 |
Execution timed out |
1101 ms |
39372 KB |
Time limit exceeded |
13 |
Execution timed out |
1084 ms |
39372 KB |
Time limit exceeded |
14 |
Execution timed out |
1080 ms |
39372 KB |
Time limit exceeded |
15 |
Execution timed out |
1094 ms |
39528 KB |
Time limit exceeded |
16 |
Execution timed out |
1089 ms |
39748 KB |
Time limit exceeded |
17 |
Execution timed out |
1087 ms |
39372 KB |
Time limit exceeded |
18 |
Execution timed out |
1094 ms |
39736 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1087 ms |
39756 KB |
Time limit exceeded |
2 |
Execution timed out |
1089 ms |
39660 KB |
Time limit exceeded |
3 |
Execution timed out |
1093 ms |
39568 KB |
Time limit exceeded |
4 |
Execution timed out |
1092 ms |
39380 KB |
Time limit exceeded |
5 |
Execution timed out |
1091 ms |
39756 KB |
Time limit exceeded |
6 |
Execution timed out |
1094 ms |
39364 KB |
Time limit exceeded |
7 |
Execution timed out |
1092 ms |
39808 KB |
Time limit exceeded |
8 |
Execution timed out |
1091 ms |
39620 KB |
Time limit exceeded |
9 |
Execution timed out |
1085 ms |
39584 KB |
Time limit exceeded |
10 |
Execution timed out |
1092 ms |
39372 KB |
Time limit exceeded |
11 |
Execution timed out |
1087 ms |
39440 KB |
Time limit exceeded |
12 |
Execution timed out |
1091 ms |
39500 KB |
Time limit exceeded |
13 |
Execution timed out |
1092 ms |
39492 KB |
Time limit exceeded |
14 |
Incorrect |
419 ms |
81168 KB |
Output isn't correct |
15 |
Execution timed out |
1085 ms |
39388 KB |
Time limit exceeded |
16 |
Execution timed out |
1092 ms |
39372 KB |
Time limit exceeded |
17 |
Execution timed out |
1095 ms |
39628 KB |
Time limit exceeded |
18 |
Execution timed out |
1097 ms |
39628 KB |
Time limit exceeded |
19 |
Execution timed out |
1097 ms |
39372 KB |
Time limit exceeded |
20 |
Execution timed out |
1097 ms |
39628 KB |
Time limit exceeded |
21 |
Incorrect |
862 ms |
79772 KB |
Output isn't correct |
22 |
Execution timed out |
1099 ms |
39756 KB |
Time limit exceeded |
23 |
Execution timed out |
1090 ms |
39628 KB |
Time limit exceeded |
24 |
Execution timed out |
1090 ms |
39500 KB |
Time limit exceeded |
25 |
Execution timed out |
1094 ms |
39372 KB |
Time limit exceeded |
26 |
Execution timed out |
1100 ms |
39364 KB |
Time limit exceeded |
27 |
Execution timed out |
1097 ms |
39748 KB |
Time limit exceeded |
28 |
Execution timed out |
1093 ms |
39372 KB |
Time limit exceeded |
29 |
Execution timed out |
1096 ms |
39748 KB |
Time limit exceeded |
30 |
Execution timed out |
1095 ms |
39756 KB |
Time limit exceeded |
31 |
Execution timed out |
1090 ms |
39372 KB |
Time limit exceeded |
32 |
Execution timed out |
1097 ms |
39392 KB |
Time limit exceeded |
33 |
Execution timed out |
1097 ms |
39364 KB |
Time limit exceeded |
34 |
Execution timed out |
1100 ms |
39756 KB |
Time limit exceeded |
35 |
Execution timed out |
1067 ms |
39372 KB |
Time limit exceeded |
36 |
Execution timed out |
1101 ms |
39748 KB |
Time limit exceeded |
37 |
Execution timed out |
1096 ms |
39748 KB |
Time limit exceeded |
38 |
Execution timed out |
1086 ms |
39372 KB |
Time limit exceeded |
39 |
Execution timed out |
1084 ms |
39372 KB |
Time limit exceeded |
40 |
Execution timed out |
1094 ms |
39404 KB |
Time limit exceeded |
41 |
Execution timed out |
1061 ms |
39800 KB |
Time limit exceeded |
42 |
Execution timed out |
1096 ms |
39348 KB |
Time limit exceeded |