#include <bits/stdc++.h>
using namespace std;
int inf = 0x3f3f3f3f;
const int MAXN = 1e4;
int dp[MAXN + 10];
int32_t main() {
int n, q;
cin >> n >> q;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
for (int i = 1; i <= MAXN; i++) {
dp[i] = inf;
for (auto u : v) dp[i] = min(dp[i], dp[i - (i % u)] + 1);
}
while (q--) {
int x;
cin >> x;
if (dp[x] == inf) cout << "oo\n";
else cout << dp[x] << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
14 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
348 KB |
Output is correct |
13 |
Correct |
42 ms |
452 KB |
Output is correct |
14 |
Correct |
34 ms |
456 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
17 ms |
520 KB |
Output is correct |
18 |
Correct |
14 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
251 ms |
484 KB |
Execution killed with signal 11 |
2 |
Execution timed out |
1073 ms |
808 KB |
Time limit exceeded |
3 |
Execution timed out |
1014 ms |
600 KB |
Time limit exceeded |
4 |
Runtime error |
66 ms |
596 KB |
Execution killed with signal 11 |
5 |
Execution timed out |
1042 ms |
648 KB |
Time limit exceeded |
6 |
Runtime error |
27 ms |
592 KB |
Execution killed with signal 11 |
7 |
Runtime error |
241 ms |
476 KB |
Execution killed with signal 11 |
8 |
Runtime error |
22 ms |
604 KB |
Execution killed with signal 11 |
9 |
Execution timed out |
1066 ms |
708 KB |
Time limit exceeded |
10 |
Execution timed out |
1075 ms |
700 KB |
Time limit exceeded |
11 |
Runtime error |
836 ms |
844 KB |
Execution killed with signal 11 |
12 |
Runtime error |
45 ms |
444 KB |
Execution killed with signal 11 |
13 |
Runtime error |
63 ms |
444 KB |
Execution killed with signal 11 |
14 |
Runtime error |
66 ms |
452 KB |
Execution killed with signal 11 |
15 |
Runtime error |
953 ms |
1120 KB |
Execution killed with signal 11 |
16 |
Execution timed out |
1022 ms |
856 KB |
Time limit exceeded |
17 |
Runtime error |
64 ms |
596 KB |
Execution killed with signal 11 |
18 |
Execution timed out |
1031 ms |
828 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1032 ms |
908 KB |
Time limit exceeded |
2 |
Execution timed out |
1051 ms |
652 KB |
Time limit exceeded |
3 |
Execution timed out |
1032 ms |
620 KB |
Time limit exceeded |
4 |
Runtime error |
81 ms |
452 KB |
Execution killed with signal 11 |
5 |
Execution timed out |
1080 ms |
828 KB |
Time limit exceeded |
6 |
Runtime error |
165 ms |
848 KB |
Execution killed with signal 11 |
7 |
Execution timed out |
1079 ms |
816 KB |
Time limit exceeded |
8 |
Execution timed out |
1053 ms |
632 KB |
Time limit exceeded |
9 |
Execution timed out |
1048 ms |
900 KB |
Time limit exceeded |
10 |
Runtime error |
122 ms |
456 KB |
Execution killed with signal 11 |
11 |
Runtime error |
105 ms |
448 KB |
Execution killed with signal 11 |
12 |
Runtime error |
122 ms |
592 KB |
Execution killed with signal 11 |
13 |
Runtime error |
615 ms |
796 KB |
Execution killed with signal 11 |
14 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
15 |
Runtime error |
113 ms |
460 KB |
Execution killed with signal 11 |
16 |
Runtime error |
148 ms |
456 KB |
Execution killed with signal 11 |
17 |
Execution timed out |
1000 ms |
880 KB |
Time limit exceeded |
18 |
Execution timed out |
1075 ms |
900 KB |
Time limit exceeded |
19 |
Runtime error |
105 ms |
596 KB |
Execution killed with signal 11 |
20 |
Execution timed out |
1027 ms |
892 KB |
Time limit exceeded |
21 |
Runtime error |
4 ms |
604 KB |
Execution killed with signal 11 |
22 |
Execution timed out |
1085 ms |
816 KB |
Time limit exceeded |
23 |
Runtime error |
613 ms |
808 KB |
Execution killed with signal 11 |
24 |
Runtime error |
26 ms |
600 KB |
Execution killed with signal 11 |
25 |
Runtime error |
63 ms |
596 KB |
Execution killed with signal 11 |
26 |
Runtime error |
72 ms |
592 KB |
Execution killed with signal 11 |
27 |
Execution timed out |
1072 ms |
1068 KB |
Time limit exceeded |
28 |
Runtime error |
23 ms |
600 KB |
Execution killed with signal 11 |
29 |
Execution timed out |
1064 ms |
824 KB |
Time limit exceeded |
30 |
Execution timed out |
1070 ms |
720 KB |
Time limit exceeded |
31 |
Runtime error |
92 ms |
596 KB |
Execution killed with signal 11 |
32 |
Runtime error |
90 ms |
592 KB |
Execution killed with signal 11 |
33 |
Runtime error |
28 ms |
456 KB |
Execution killed with signal 11 |
34 |
Execution timed out |
1059 ms |
1076 KB |
Time limit exceeded |
35 |
Runtime error |
43 ms |
464 KB |
Execution killed with signal 11 |
36 |
Execution timed out |
1022 ms |
788 KB |
Time limit exceeded |
37 |
Execution timed out |
1050 ms |
820 KB |
Time limit exceeded |
38 |
Runtime error |
168 ms |
468 KB |
Execution killed with signal 11 |
39 |
Runtime error |
61 ms |
448 KB |
Execution killed with signal 11 |
40 |
Runtime error |
190 ms |
596 KB |
Execution killed with signal 11 |
41 |
Execution timed out |
1039 ms |
856 KB |
Time limit exceeded |
42 |
Runtime error |
73 ms |
596 KB |
Execution killed with signal 11 |