#include<bits/stdc++.h>
using namespace std;
#define maxa 10000000
#define maxn 100005
#define pii pair<int,int>
int q,m,dp[maxa+5],pp[maxa+5];
vector<int> pr;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
cin >> m >> q;
for(int i=1;i<=m;i++){
int p;cin >> p;
for(int j=0;j<=maxa;j+=p) pp[j]=p;
}
int pre=0,lst=0,num=0,dead=-1;
while(true){
if(pre>lst){
dead=pre;
break;
}
int nxt=lst;
for(int i=pre;i<=lst;i++) nxt=max(nxt,i+pp[i]-1);
pre=lst+1;lst=nxt;num++;
for(int i=pre;i<=min(lst,maxa);i++) dp[i]=num;
if(lst>maxa) break;
}
for(int i=1;i<=q;i++){
int a;cin >> a;
if(a>=dead && dead!=-1) cout << "oo\n";
else cout << dp[a] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
39456 KB |
Output is correct |
2 |
Correct |
67 ms |
78484 KB |
Output is correct |
3 |
Correct |
36 ms |
40472 KB |
Output is correct |
4 |
Correct |
49 ms |
78480 KB |
Output is correct |
5 |
Correct |
63 ms |
78488 KB |
Output is correct |
6 |
Correct |
22 ms |
39380 KB |
Output is correct |
7 |
Correct |
43 ms |
40464 KB |
Output is correct |
8 |
Correct |
35 ms |
42896 KB |
Output is correct |
9 |
Correct |
97 ms |
78488 KB |
Output is correct |
10 |
Correct |
109 ms |
78488 KB |
Output is correct |
11 |
Correct |
97 ms |
78488 KB |
Output is correct |
12 |
Correct |
59 ms |
78508 KB |
Output is correct |
13 |
Correct |
171 ms |
78512 KB |
Output is correct |
14 |
Correct |
164 ms |
78488 KB |
Output is correct |
15 |
Correct |
69 ms |
78560 KB |
Output is correct |
16 |
Correct |
75 ms |
78484 KB |
Output is correct |
17 |
Correct |
67 ms |
78496 KB |
Output is correct |
18 |
Correct |
62 ms |
78520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
78560 KB |
Output is correct |
2 |
Correct |
69 ms |
78508 KB |
Output is correct |
3 |
Correct |
174 ms |
78492 KB |
Output is correct |
4 |
Correct |
76 ms |
78484 KB |
Output is correct |
5 |
Correct |
144 ms |
78588 KB |
Output is correct |
6 |
Correct |
71 ms |
78484 KB |
Output is correct |
7 |
Correct |
60 ms |
78556 KB |
Output is correct |
8 |
Correct |
73 ms |
78552 KB |
Output is correct |
9 |
Correct |
146 ms |
78484 KB |
Output is correct |
10 |
Correct |
186 ms |
78484 KB |
Output is correct |
11 |
Correct |
179 ms |
78612 KB |
Output is correct |
12 |
Correct |
106 ms |
78484 KB |
Output is correct |
13 |
Correct |
52 ms |
78572 KB |
Output is correct |
14 |
Correct |
82 ms |
78500 KB |
Output is correct |
15 |
Correct |
193 ms |
78484 KB |
Output is correct |
16 |
Correct |
75 ms |
78572 KB |
Output is correct |
17 |
Correct |
164 ms |
78468 KB |
Output is correct |
18 |
Correct |
157 ms |
78484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
189 ms |
78592 KB |
Output is correct |
2 |
Correct |
190 ms |
78612 KB |
Output is correct |
3 |
Correct |
187 ms |
78740 KB |
Output is correct |
4 |
Correct |
143 ms |
78796 KB |
Output is correct |
5 |
Correct |
102 ms |
78732 KB |
Output is correct |
6 |
Correct |
164 ms |
78736 KB |
Output is correct |
7 |
Correct |
141 ms |
78588 KB |
Output is correct |
8 |
Correct |
153 ms |
78616 KB |
Output is correct |
9 |
Correct |
155 ms |
78600 KB |
Output is correct |
10 |
Correct |
122 ms |
78612 KB |
Output is correct |
11 |
Correct |
121 ms |
78608 KB |
Output is correct |
12 |
Correct |
142 ms |
78628 KB |
Output is correct |
13 |
Correct |
240 ms |
78744 KB |
Output is correct |
14 |
Correct |
131 ms |
79064 KB |
Output is correct |
15 |
Correct |
160 ms |
78612 KB |
Output is correct |
16 |
Correct |
216 ms |
78612 KB |
Output is correct |
17 |
Correct |
162 ms |
78612 KB |
Output is correct |
18 |
Correct |
239 ms |
78604 KB |
Output is correct |
19 |
Correct |
68 ms |
78568 KB |
Output is correct |
20 |
Correct |
205 ms |
78728 KB |
Output is correct |
21 |
Correct |
138 ms |
79168 KB |
Output is correct |
22 |
Correct |
226 ms |
78740 KB |
Output is correct |
23 |
Correct |
115 ms |
78756 KB |
Output is correct |
24 |
Correct |
88 ms |
78788 KB |
Output is correct |
25 |
Correct |
143 ms |
78872 KB |
Output is correct |
26 |
Correct |
132 ms |
78816 KB |
Output is correct |
27 |
Correct |
241 ms |
78608 KB |
Output is correct |
28 |
Correct |
83 ms |
78864 KB |
Output is correct |
29 |
Correct |
223 ms |
78776 KB |
Output is correct |
30 |
Correct |
177 ms |
78744 KB |
Output is correct |
31 |
Correct |
134 ms |
78856 KB |
Output is correct |
32 |
Correct |
109 ms |
78740 KB |
Output is correct |
33 |
Correct |
74 ms |
78760 KB |
Output is correct |
34 |
Correct |
139 ms |
78620 KB |
Output is correct |
35 |
Correct |
85 ms |
78872 KB |
Output is correct |
36 |
Correct |
257 ms |
78684 KB |
Output is correct |
37 |
Correct |
93 ms |
78740 KB |
Output is correct |
38 |
Correct |
173 ms |
78868 KB |
Output is correct |
39 |
Correct |
85 ms |
78832 KB |
Output is correct |
40 |
Correct |
136 ms |
78836 KB |
Output is correct |
41 |
Correct |
126 ms |
78592 KB |
Output is correct |
42 |
Correct |
168 ms |
79000 KB |
Output is correct |