// Zende bad Shoma nasime faghat !
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;
int m, Q;
int p[N], ans[N];
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
memset(ans, -1, sizeof ans);
cin >> m >> Q;
for(int i = 0; i < m; i++) cin >> p[i];
vector< pair<int, int> > V;
int v;
for(int i = 0; i < Q; i++){
cin >> v;
V.pb({v, i});
}
sort(all(V));
int po = 0;
int R = 0, R2, cnt = 0;
while(R <= 10000000){
R2 = R;
for(int i = 0; i < m; i++)
R2 = max(R2, R - (R % p[i]) + p[i] - 1);
cnt ++;
while((po < (int) V.size()) && (V[po].F <= R2)){
ans[V[po ++].S] = cnt;
}
if(R2 == R) break;
R = R2;
}
for(int i = 0; i < Q; i++){
if(ans[i] == -1) cout << "oo\n";
else cout << ans[i] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1152 KB |
Output is correct |
2 |
Correct |
9 ms |
1152 KB |
Output is correct |
3 |
Correct |
2 ms |
1184 KB |
Output is correct |
4 |
Correct |
6 ms |
1408 KB |
Output is correct |
5 |
Correct |
16 ms |
1152 KB |
Output is correct |
6 |
Correct |
1 ms |
1152 KB |
Output is correct |
7 |
Correct |
2 ms |
1152 KB |
Output is correct |
8 |
Correct |
3 ms |
1152 KB |
Output is correct |
9 |
Correct |
26 ms |
1152 KB |
Output is correct |
10 |
Correct |
18 ms |
1152 KB |
Output is correct |
11 |
Correct |
17 ms |
1152 KB |
Output is correct |
12 |
Correct |
4 ms |
1152 KB |
Output is correct |
13 |
Correct |
10 ms |
1280 KB |
Output is correct |
14 |
Correct |
11 ms |
1408 KB |
Output is correct |
15 |
Correct |
8 ms |
1152 KB |
Output is correct |
16 |
Correct |
8 ms |
1152 KB |
Output is correct |
17 |
Correct |
12 ms |
1408 KB |
Output is correct |
18 |
Correct |
6 ms |
1408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1280 KB |
Output is correct |
2 |
Correct |
13 ms |
2208 KB |
Output is correct |
3 |
Correct |
13 ms |
1920 KB |
Output is correct |
4 |
Correct |
4 ms |
1152 KB |
Output is correct |
5 |
Correct |
10 ms |
1660 KB |
Output is correct |
6 |
Correct |
2 ms |
1152 KB |
Output is correct |
7 |
Correct |
3 ms |
1280 KB |
Output is correct |
8 |
Correct |
4 ms |
1152 KB |
Output is correct |
9 |
Correct |
15 ms |
1920 KB |
Output is correct |
10 |
Correct |
12 ms |
1920 KB |
Output is correct |
11 |
Correct |
10 ms |
1536 KB |
Output is correct |
12 |
Correct |
4 ms |
1152 KB |
Output is correct |
13 |
Correct |
2 ms |
1152 KB |
Output is correct |
14 |
Correct |
3 ms |
1152 KB |
Output is correct |
15 |
Correct |
10 ms |
1536 KB |
Output is correct |
16 |
Correct |
15 ms |
2176 KB |
Output is correct |
17 |
Correct |
7 ms |
1152 KB |
Output is correct |
18 |
Correct |
17 ms |
2304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
2688 KB |
Output is correct |
2 |
Correct |
20 ms |
2240 KB |
Output is correct |
3 |
Correct |
23 ms |
2812 KB |
Output is correct |
4 |
Correct |
32 ms |
3068 KB |
Output is correct |
5 |
Correct |
69 ms |
4208 KB |
Output is correct |
6 |
Correct |
46 ms |
3060 KB |
Output is correct |
7 |
Correct |
32 ms |
3456 KB |
Output is correct |
8 |
Correct |
21 ms |
2688 KB |
Output is correct |
9 |
Correct |
22 ms |
2688 KB |
Output is correct |
10 |
Correct |
9 ms |
1536 KB |
Output is correct |
11 |
Correct |
11 ms |
1664 KB |
Output is correct |
12 |
Correct |
12 ms |
1792 KB |
Output is correct |
13 |
Correct |
28 ms |
3324 KB |
Output is correct |
14 |
Correct |
44 ms |
3308 KB |
Output is correct |
15 |
Correct |
13 ms |
1792 KB |
Output is correct |
16 |
Correct |
14 ms |
1792 KB |
Output is correct |
17 |
Correct |
13 ms |
1920 KB |
Output is correct |
18 |
Correct |
19 ms |
2304 KB |
Output is correct |
19 |
Correct |
8 ms |
1792 KB |
Output is correct |
20 |
Correct |
25 ms |
2812 KB |
Output is correct |
21 |
Correct |
33 ms |
3448 KB |
Output is correct |
22 |
Correct |
44 ms |
4168 KB |
Output is correct |
23 |
Correct |
42 ms |
3348 KB |
Output is correct |
24 |
Correct |
30 ms |
3068 KB |
Output is correct |
25 |
Correct |
32 ms |
3068 KB |
Output is correct |
26 |
Correct |
33 ms |
3068 KB |
Output is correct |
27 |
Correct |
29 ms |
3328 KB |
Output is correct |
28 |
Correct |
25 ms |
3184 KB |
Output is correct |
29 |
Correct |
52 ms |
4084 KB |
Output is correct |
30 |
Correct |
42 ms |
3824 KB |
Output is correct |
31 |
Correct |
30 ms |
3068 KB |
Output is correct |
32 |
Correct |
30 ms |
3068 KB |
Output is correct |
33 |
Correct |
28 ms |
3068 KB |
Output is correct |
34 |
Correct |
28 ms |
3328 KB |
Output is correct |
35 |
Correct |
25 ms |
3184 KB |
Output is correct |
36 |
Correct |
44 ms |
4092 KB |
Output is correct |
37 |
Correct |
43 ms |
4208 KB |
Output is correct |
38 |
Correct |
33 ms |
3068 KB |
Output is correct |
39 |
Correct |
31 ms |
3068 KB |
Output is correct |
40 |
Correct |
33 ms |
3068 KB |
Output is correct |
41 |
Correct |
27 ms |
3328 KB |
Output is correct |
42 |
Correct |
29 ms |
3312 KB |
Output is correct |