#include<bits/stdc++.h>
using namespace std;
const int N = 1e7 + 1;
const int inf = 1e9 + 7;
int t[N << 1];
int f[N];
void Min(int &x,int y) {
if (x > y)
x = y;
}
void upd(int l,int r,int v) {
l += N - 1;
r += N;
for(; l < r ; l >>= 1, r >>= 1) {
if (l & 1) Min(t[l++],v);
if (r & 1) Min(t[--r],v);
}
}
int get(int p) {
int ans = inf;
for(p += N - 1 ; p ; p >>= 1)
Min(ans,t[p]);
return ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int m; cin >> m;
int Q; cin >> Q;
for(int i = 1 ; i < N + N ; ++i)
t[i] = inf;
for(int i = 0 ; i < m ; ++i) {
int x; cin >> x;
for(int j = 0 ; j < N ; j += x)
upd(j,min(j + x - 1,N),j);
}
for(int i = 1 ; i < N ; ++i) {
int p = get(i);
if (p < i)
f[i] = f[p] + 1;
else
f[i] = inf;
}
for(int i = 0 ; i < Q ; ++i) {
int x; cin >> x;
if (f[x] >= inf)
cout << "oo\n";
else
cout << f[x] << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
381 ms |
117752 KB |
Output is correct |
2 |
Correct |
582 ms |
117768 KB |
Output is correct |
3 |
Correct |
427 ms |
118008 KB |
Output is correct |
4 |
Correct |
436 ms |
117956 KB |
Output is correct |
5 |
Correct |
459 ms |
117800 KB |
Output is correct |
6 |
Correct |
379 ms |
117864 KB |
Output is correct |
7 |
Correct |
427 ms |
118008 KB |
Output is correct |
8 |
Correct |
452 ms |
117824 KB |
Output is correct |
9 |
Correct |
521 ms |
117880 KB |
Output is correct |
10 |
Correct |
630 ms |
117752 KB |
Output is correct |
11 |
Correct |
604 ms |
117824 KB |
Output is correct |
12 |
Correct |
422 ms |
118136 KB |
Output is correct |
13 |
Execution timed out |
1075 ms |
78588 KB |
Time limit exceeded |
14 |
Execution timed out |
1051 ms |
78584 KB |
Time limit exceeded |
15 |
Correct |
593 ms |
117896 KB |
Output is correct |
16 |
Correct |
582 ms |
117808 KB |
Output is correct |
17 |
Correct |
605 ms |
118008 KB |
Output is correct |
18 |
Correct |
435 ms |
118008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
647 ms |
117880 KB |
Output is correct |
2 |
Correct |
725 ms |
118584 KB |
Output is correct |
3 |
Execution timed out |
1076 ms |
78712 KB |
Time limit exceeded |
4 |
Correct |
849 ms |
117752 KB |
Output is correct |
5 |
Execution timed out |
1082 ms |
78808 KB |
Time limit exceeded |
6 |
Correct |
620 ms |
117720 KB |
Output is correct |
7 |
Correct |
652 ms |
117860 KB |
Output is correct |
8 |
Correct |
772 ms |
117716 KB |
Output is correct |
9 |
Execution timed out |
1084 ms |
78684 KB |
Time limit exceeded |
10 |
Execution timed out |
1082 ms |
78712 KB |
Time limit exceeded |
11 |
Execution timed out |
1081 ms |
78584 KB |
Time limit exceeded |
12 |
Execution timed out |
1047 ms |
117880 KB |
Time limit exceeded |
13 |
Correct |
509 ms |
117852 KB |
Output is correct |
14 |
Correct |
865 ms |
117836 KB |
Output is correct |
15 |
Execution timed out |
1081 ms |
78724 KB |
Time limit exceeded |
16 |
Correct |
729 ms |
118520 KB |
Output is correct |
17 |
Execution timed out |
1091 ms |
78584 KB |
Time limit exceeded |
18 |
Execution timed out |
1085 ms |
78844 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1086 ms |
78688 KB |
Time limit exceeded |
2 |
Execution timed out |
1092 ms |
78712 KB |
Time limit exceeded |
3 |
Execution timed out |
1083 ms |
78684 KB |
Time limit exceeded |
4 |
Execution timed out |
1053 ms |
118744 KB |
Time limit exceeded |
5 |
Correct |
906 ms |
119488 KB |
Output is correct |
6 |
Execution timed out |
1092 ms |
78692 KB |
Time limit exceeded |
7 |
Execution timed out |
1055 ms |
78712 KB |
Time limit exceeded |
8 |
Execution timed out |
1097 ms |
78712 KB |
Time limit exceeded |
9 |
Execution timed out |
1084 ms |
78720 KB |
Time limit exceeded |
10 |
Execution timed out |
1087 ms |
78724 KB |
Time limit exceeded |
11 |
Execution timed out |
1086 ms |
102136 KB |
Time limit exceeded |
12 |
Execution timed out |
1066 ms |
78712 KB |
Time limit exceeded |
13 |
Execution timed out |
1086 ms |
78712 KB |
Time limit exceeded |
14 |
Correct |
747 ms |
119032 KB |
Output is correct |
15 |
Execution timed out |
1040 ms |
78712 KB |
Time limit exceeded |
16 |
Execution timed out |
1084 ms |
78584 KB |
Time limit exceeded |
17 |
Execution timed out |
1073 ms |
78716 KB |
Time limit exceeded |
18 |
Execution timed out |
1088 ms |
78584 KB |
Time limit exceeded |
19 |
Correct |
579 ms |
118176 KB |
Output is correct |
20 |
Execution timed out |
1087 ms |
78584 KB |
Time limit exceeded |
21 |
Execution timed out |
1058 ms |
119260 KB |
Time limit exceeded |
22 |
Execution timed out |
1072 ms |
78712 KB |
Time limit exceeded |
23 |
Execution timed out |
1014 ms |
119104 KB |
Time limit exceeded |
24 |
Correct |
584 ms |
118704 KB |
Output is correct |
25 |
Execution timed out |
1083 ms |
86776 KB |
Time limit exceeded |
26 |
Execution timed out |
1058 ms |
119016 KB |
Time limit exceeded |
27 |
Execution timed out |
1083 ms |
78584 KB |
Time limit exceeded |
28 |
Incorrect |
630 ms |
119032 KB |
Output isn't correct |
29 |
Execution timed out |
1090 ms |
78712 KB |
Time limit exceeded |
30 |
Execution timed out |
1067 ms |
78628 KB |
Time limit exceeded |
31 |
Correct |
738 ms |
118648 KB |
Output is correct |
32 |
Correct |
960 ms |
118780 KB |
Output is correct |
33 |
Correct |
484 ms |
118680 KB |
Output is correct |
34 |
Execution timed out |
1082 ms |
78584 KB |
Time limit exceeded |
35 |
Incorrect |
744 ms |
118976 KB |
Output isn't correct |
36 |
Execution timed out |
1073 ms |
78712 KB |
Time limit exceeded |
37 |
Correct |
907 ms |
119516 KB |
Output is correct |
38 |
Execution timed out |
1083 ms |
78584 KB |
Time limit exceeded |
39 |
Correct |
739 ms |
118860 KB |
Output is correct |
40 |
Execution timed out |
1082 ms |
78840 KB |
Time limit exceeded |
41 |
Execution timed out |
1072 ms |
79324 KB |
Time limit exceeded |
42 |
Execution timed out |
1085 ms |
78584 KB |
Time limit exceeded |