#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];
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];
int ma=0;
for(int i=0;i<m;++i) if(z%a[i]>ma) ma=z%a[i];
return sol(z-ma)+1;
}
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);
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 |
Correct |
16 ms |
39452 KB |
Output is correct |
2 |
Correct |
17 ms |
39372 KB |
Output is correct |
3 |
Correct |
15 ms |
39436 KB |
Output is correct |
4 |
Correct |
23 ms |
39372 KB |
Output is correct |
5 |
Correct |
15 ms |
39372 KB |
Output is correct |
6 |
Correct |
18 ms |
39452 KB |
Output is correct |
7 |
Correct |
17 ms |
39432 KB |
Output is correct |
8 |
Correct |
16 ms |
39364 KB |
Output is correct |
9 |
Correct |
15 ms |
39372 KB |
Output is correct |
10 |
Correct |
21 ms |
39540 KB |
Output is correct |
11 |
Correct |
25 ms |
39456 KB |
Output is correct |
12 |
Correct |
17 ms |
39372 KB |
Output is correct |
13 |
Correct |
21 ms |
39372 KB |
Output is correct |
14 |
Correct |
63 ms |
39504 KB |
Output is correct |
15 |
Correct |
16 ms |
39456 KB |
Output is correct |
16 |
Correct |
17 ms |
39372 KB |
Output is correct |
17 |
Correct |
46 ms |
39416 KB |
Output is correct |
18 |
Correct |
24 ms |
39372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
39508 KB |
Output is correct |
2 |
Correct |
26 ms |
39832 KB |
Output is correct |
3 |
Correct |
22 ms |
39688 KB |
Output is correct |
4 |
Correct |
18 ms |
39372 KB |
Output is correct |
5 |
Correct |
22 ms |
39612 KB |
Output is correct |
6 |
Correct |
20 ms |
39432 KB |
Output is correct |
7 |
Correct |
18 ms |
39572 KB |
Output is correct |
8 |
Correct |
17 ms |
39400 KB |
Output is correct |
9 |
Correct |
24 ms |
39772 KB |
Output is correct |
10 |
Correct |
24 ms |
39680 KB |
Output is correct |
11 |
Correct |
24 ms |
39608 KB |
Output is correct |
12 |
Correct |
19 ms |
39424 KB |
Output is correct |
13 |
Correct |
17 ms |
39372 KB |
Output is correct |
14 |
Correct |
17 ms |
39372 KB |
Output is correct |
15 |
Correct |
22 ms |
39532 KB |
Output is correct |
16 |
Correct |
26 ms |
39784 KB |
Output is correct |
17 |
Correct |
22 ms |
39372 KB |
Output is correct |
18 |
Correct |
28 ms |
39748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
39568 KB |
Time limit exceeded |
2 |
Execution timed out |
1093 ms |
39628 KB |
Time limit exceeded |
3 |
Execution timed out |
1087 ms |
39628 KB |
Time limit exceeded |
4 |
Execution timed out |
1063 ms |
39448 KB |
Time limit exceeded |
5 |
Execution timed out |
1091 ms |
39748 KB |
Time limit exceeded |
6 |
Execution timed out |
1099 ms |
39372 KB |
Time limit exceeded |
7 |
Execution timed out |
1090 ms |
39744 KB |
Time limit exceeded |
8 |
Execution timed out |
1096 ms |
39552 KB |
Time limit exceeded |
9 |
Execution timed out |
1095 ms |
39644 KB |
Time limit exceeded |
10 |
Execution timed out |
1098 ms |
39500 KB |
Time limit exceeded |
11 |
Execution timed out |
1093 ms |
39456 KB |
Time limit exceeded |
12 |
Execution timed out |
1092 ms |
39372 KB |
Time limit exceeded |
13 |
Execution timed out |
1091 ms |
39500 KB |
Time limit exceeded |
14 |
Execution timed out |
1098 ms |
39372 KB |
Time limit exceeded |
15 |
Execution timed out |
1086 ms |
39372 KB |
Time limit exceeded |
16 |
Execution timed out |
1090 ms |
39372 KB |
Time limit exceeded |
17 |
Execution timed out |
1044 ms |
39628 KB |
Time limit exceeded |
18 |
Execution timed out |
1095 ms |
39628 KB |
Time limit exceeded |
19 |
Execution timed out |
1087 ms |
39460 KB |
Time limit exceeded |
20 |
Execution timed out |
1087 ms |
39720 KB |
Time limit exceeded |
21 |
Execution timed out |
1092 ms |
39372 KB |
Time limit exceeded |
22 |
Execution timed out |
1038 ms |
39884 KB |
Time limit exceeded |
23 |
Execution timed out |
1100 ms |
39496 KB |
Time limit exceeded |
24 |
Execution timed out |
1089 ms |
39568 KB |
Time limit exceeded |
25 |
Execution timed out |
1091 ms |
39452 KB |
Time limit exceeded |
26 |
Execution timed out |
1091 ms |
39372 KB |
Time limit exceeded |
27 |
Execution timed out |
1091 ms |
39752 KB |
Time limit exceeded |
28 |
Execution timed out |
1087 ms |
39448 KB |
Time limit exceeded |
29 |
Execution timed out |
1098 ms |
39712 KB |
Time limit exceeded |
30 |
Execution timed out |
1092 ms |
39620 KB |
Time limit exceeded |
31 |
Execution timed out |
1094 ms |
39456 KB |
Time limit exceeded |
32 |
Execution timed out |
1097 ms |
39448 KB |
Time limit exceeded |
33 |
Execution timed out |
1103 ms |
39440 KB |
Time limit exceeded |
34 |
Execution timed out |
1089 ms |
39756 KB |
Time limit exceeded |
35 |
Execution timed out |
1094 ms |
39440 KB |
Time limit exceeded |
36 |
Execution timed out |
1099 ms |
39768 KB |
Time limit exceeded |
37 |
Execution timed out |
1098 ms |
39756 KB |
Time limit exceeded |
38 |
Execution timed out |
1093 ms |
39372 KB |
Time limit exceeded |
39 |
Execution timed out |
1096 ms |
39452 KB |
Time limit exceeded |
40 |
Execution timed out |
1092 ms |
39480 KB |
Time limit exceeded |
41 |
Execution timed out |
1102 ms |
39828 KB |
Time limit exceeded |
42 |
Execution timed out |
1056 ms |
39352 KB |
Time limit exceeded |