#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 ]=a[i]-1;
}
}
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 |
241 ms |
78476 KB |
Output isn't correct |
2 |
Incorrect |
868 ms |
78480 KB |
Output isn't correct |
3 |
Incorrect |
187 ms |
78480 KB |
Output isn't correct |
4 |
Execution timed out |
1092 ms |
39440 KB |
Time limit exceeded |
5 |
Incorrect |
604 ms |
78472 KB |
Output isn't correct |
6 |
Incorrect |
249 ms |
78480 KB |
Output isn't correct |
7 |
Incorrect |
191 ms |
78472 KB |
Output isn't correct |
8 |
Incorrect |
165 ms |
78492 KB |
Output isn't correct |
9 |
Incorrect |
201 ms |
78476 KB |
Output isn't correct |
10 |
Incorrect |
306 ms |
78476 KB |
Output isn't correct |
11 |
Incorrect |
545 ms |
78476 KB |
Output isn't correct |
12 |
Execution timed out |
1079 ms |
39372 KB |
Time limit exceeded |
13 |
Execution timed out |
1088 ms |
39500 KB |
Time limit exceeded |
14 |
Execution timed out |
1088 ms |
39344 KB |
Time limit exceeded |
15 |
Incorrect |
711 ms |
78488 KB |
Output isn't correct |
16 |
Incorrect |
847 ms |
78480 KB |
Output isn't correct |
17 |
Execution timed out |
1092 ms |
39372 KB |
Time limit exceeded |
18 |
Execution timed out |
1059 ms |
39372 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1093 ms |
39456 KB |
Time limit exceeded |
2 |
Execution timed out |
1099 ms |
39756 KB |
Time limit exceeded |
3 |
Execution timed out |
1091 ms |
39628 KB |
Time limit exceeded |
4 |
Execution timed out |
1088 ms |
39372 KB |
Time limit exceeded |
5 |
Execution timed out |
1070 ms |
39644 KB |
Time limit exceeded |
6 |
Execution timed out |
1097 ms |
39372 KB |
Time limit exceeded |
7 |
Execution timed out |
1071 ms |
39500 KB |
Time limit exceeded |
8 |
Execution timed out |
1086 ms |
39372 KB |
Time limit exceeded |
9 |
Execution timed out |
1079 ms |
39628 KB |
Time limit exceeded |
10 |
Execution timed out |
1090 ms |
39628 KB |
Time limit exceeded |
11 |
Execution timed out |
1086 ms |
39500 KB |
Time limit exceeded |
12 |
Execution timed out |
1089 ms |
39344 KB |
Time limit exceeded |
13 |
Execution timed out |
1068 ms |
39372 KB |
Time limit exceeded |
14 |
Execution timed out |
1085 ms |
39372 KB |
Time limit exceeded |
15 |
Execution timed out |
1095 ms |
39580 KB |
Time limit exceeded |
16 |
Execution timed out |
1087 ms |
39756 KB |
Time limit exceeded |
17 |
Execution timed out |
1082 ms |
39372 KB |
Time limit exceeded |
18 |
Execution timed out |
1094 ms |
39756 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1018 ms |
39628 KB |
Time limit exceeded |
2 |
Execution timed out |
1094 ms |
39620 KB |
Time limit exceeded |
3 |
Execution timed out |
1084 ms |
39612 KB |
Time limit exceeded |
4 |
Execution timed out |
1093 ms |
39372 KB |
Time limit exceeded |
5 |
Execution timed out |
1092 ms |
39748 KB |
Time limit exceeded |
6 |
Execution timed out |
1088 ms |
39432 KB |
Time limit exceeded |
7 |
Execution timed out |
1093 ms |
39756 KB |
Time limit exceeded |
8 |
Execution timed out |
1081 ms |
39628 KB |
Time limit exceeded |
9 |
Execution timed out |
1091 ms |
39536 KB |
Time limit exceeded |
10 |
Execution timed out |
1098 ms |
39372 KB |
Time limit exceeded |
11 |
Execution timed out |
1088 ms |
39372 KB |
Time limit exceeded |
12 |
Execution timed out |
1091 ms |
39372 KB |
Time limit exceeded |
13 |
Execution timed out |
1087 ms |
39628 KB |
Time limit exceeded |
14 |
Incorrect |
411 ms |
81124 KB |
Output isn't correct |
15 |
Execution timed out |
1092 ms |
39372 KB |
Time limit exceeded |
16 |
Execution timed out |
1096 ms |
39364 KB |
Time limit exceeded |
17 |
Execution timed out |
1090 ms |
39628 KB |
Time limit exceeded |
18 |
Execution timed out |
1097 ms |
39628 KB |
Time limit exceeded |
19 |
Execution timed out |
1091 ms |
39372 KB |
Time limit exceeded |
20 |
Execution timed out |
1098 ms |
39628 KB |
Time limit exceeded |
21 |
Incorrect |
802 ms |
79812 KB |
Output isn't correct |
22 |
Execution timed out |
1099 ms |
39756 KB |
Time limit exceeded |
23 |
Execution timed out |
1095 ms |
39500 KB |
Time limit exceeded |
24 |
Execution timed out |
1063 ms |
39372 KB |
Time limit exceeded |
25 |
Execution timed out |
1097 ms |
39500 KB |
Time limit exceeded |
26 |
Execution timed out |
1098 ms |
39372 KB |
Time limit exceeded |
27 |
Execution timed out |
1098 ms |
39756 KB |
Time limit exceeded |
28 |
Execution timed out |
1101 ms |
39432 KB |
Time limit exceeded |
29 |
Execution timed out |
1093 ms |
39756 KB |
Time limit exceeded |
30 |
Execution timed out |
1098 ms |
39648 KB |
Time limit exceeded |
31 |
Execution timed out |
1090 ms |
39372 KB |
Time limit exceeded |
32 |
Execution timed out |
1095 ms |
39372 KB |
Time limit exceeded |
33 |
Execution timed out |
1101 ms |
39372 KB |
Time limit exceeded |
34 |
Execution timed out |
1092 ms |
39756 KB |
Time limit exceeded |
35 |
Execution timed out |
1096 ms |
39372 KB |
Time limit exceeded |
36 |
Execution timed out |
1090 ms |
39756 KB |
Time limit exceeded |
37 |
Execution timed out |
1098 ms |
39756 KB |
Time limit exceeded |
38 |
Execution timed out |
1053 ms |
39372 KB |
Time limit exceeded |
39 |
Execution timed out |
1084 ms |
39444 KB |
Time limit exceeded |
40 |
Execution timed out |
1095 ms |
39372 KB |
Time limit exceeded |
41 |
Execution timed out |
1086 ms |
39756 KB |
Time limit exceeded |
42 |
Execution timed out |
1101 ms |
39464 KB |
Time limit exceeded |