#include <iostream>
#include <string.h>
using namespace std;
const int N = 1e5+5, MAXN = 1e7+7, INF = 1e9+9;
int n, q, x, p[N], dp[MAXN];
int solve(int x)
{
//cout << x << endl;
if (dp[x] != -1)
return dp[x];
int mn = INF;
for (int i = 0; i < n; i++)
{
if (x < p[i])
{
dp[x] = 1;
return dp[x];
}
if (x % p[i] == 0) continue;
mn = min(mn,solve(x-(x%p[i]))+1);
}
dp[x] = mn;
return dp[x];
}
int main()
{
memset(dp,-1,sizeof dp);
cin >> n >> q;
for (int i = 0; i < n; i++)
{
cin >> p[i];
}
while(q--)
{
cin >> x;
solve(x);
if (dp[x] == INF) cout << "oo\n";
else cout << dp[x] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
39416 KB |
Output is correct |
2 |
Correct |
37 ms |
39544 KB |
Output is correct |
3 |
Correct |
35 ms |
39544 KB |
Output is correct |
4 |
Correct |
69 ms |
39544 KB |
Output is correct |
5 |
Correct |
36 ms |
39416 KB |
Output is correct |
6 |
Correct |
38 ms |
39544 KB |
Output is correct |
7 |
Correct |
35 ms |
39544 KB |
Output is correct |
8 |
Correct |
35 ms |
39544 KB |
Output is correct |
9 |
Correct |
35 ms |
39416 KB |
Output is correct |
10 |
Correct |
44 ms |
39580 KB |
Output is correct |
11 |
Correct |
40 ms |
39544 KB |
Output is correct |
12 |
Correct |
35 ms |
39544 KB |
Output is correct |
13 |
Correct |
72 ms |
39672 KB |
Output is correct |
14 |
Correct |
92 ms |
39544 KB |
Output is correct |
15 |
Correct |
37 ms |
39416 KB |
Output is correct |
16 |
Correct |
38 ms |
39460 KB |
Output is correct |
17 |
Correct |
70 ms |
39676 KB |
Output is correct |
18 |
Correct |
70 ms |
39600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1053 ms |
42360 KB |
Time limit exceeded |
2 |
Execution timed out |
1084 ms |
53540 KB |
Time limit exceeded |
3 |
Execution timed out |
1055 ms |
122604 KB |
Time limit exceeded |
4 |
Execution timed out |
1076 ms |
60664 KB |
Time limit exceeded |
5 |
Execution timed out |
1091 ms |
64888 KB |
Time limit exceeded |
6 |
Execution timed out |
1078 ms |
47352 KB |
Time limit exceeded |
7 |
Execution timed out |
1093 ms |
42360 KB |
Time limit exceeded |
8 |
Execution timed out |
1086 ms |
47736 KB |
Time limit exceeded |
9 |
Execution timed out |
1074 ms |
58492 KB |
Time limit exceeded |
10 |
Execution timed out |
1089 ms |
122616 KB |
Time limit exceeded |
11 |
Execution timed out |
1100 ms |
213852 KB |
Time limit exceeded |
12 |
Execution timed out |
1089 ms |
89720 KB |
Time limit exceeded |
13 |
Execution timed out |
1078 ms |
61816 KB |
Time limit exceeded |
14 |
Execution timed out |
1088 ms |
60792 KB |
Time limit exceeded |
15 |
Execution timed out |
1081 ms |
82804 KB |
Time limit exceeded |
16 |
Execution timed out |
1081 ms |
53624 KB |
Time limit exceeded |
17 |
Execution timed out |
1062 ms |
211420 KB |
Time limit exceeded |
18 |
Execution timed out |
1098 ms |
155864 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1047 ms |
199956 KB |
Time limit exceeded |
2 |
Execution timed out |
1076 ms |
48888 KB |
Time limit exceeded |
3 |
Execution timed out |
1076 ms |
162552 KB |
Time limit exceeded |
4 |
Execution timed out |
1042 ms |
112248 KB |
Time limit exceeded |
5 |
Execution timed out |
1071 ms |
41084 KB |
Time limit exceeded |
6 |
Execution timed out |
1091 ms |
152012 KB |
Time limit exceeded |
7 |
Execution timed out |
1079 ms |
64120 KB |
Time limit exceeded |
8 |
Execution timed out |
1086 ms |
199800 KB |
Time limit exceeded |
9 |
Execution timed out |
1092 ms |
199800 KB |
Time limit exceeded |
10 |
Execution timed out |
1075 ms |
44792 KB |
Time limit exceeded |
11 |
Execution timed out |
1076 ms |
69368 KB |
Time limit exceeded |
12 |
Execution timed out |
1089 ms |
125872 KB |
Time limit exceeded |
13 |
Execution timed out |
1079 ms |
98140 KB |
Time limit exceeded |
14 |
Execution timed out |
1082 ms |
143228 KB |
Time limit exceeded |
15 |
Execution timed out |
1097 ms |
205444 KB |
Time limit exceeded |
16 |
Execution timed out |
1085 ms |
137976 KB |
Time limit exceeded |
17 |
Execution timed out |
1083 ms |
51064 KB |
Time limit exceeded |
18 |
Execution timed out |
1070 ms |
49052 KB |
Time limit exceeded |
19 |
Execution timed out |
1073 ms |
48376 KB |
Time limit exceeded |
20 |
Execution timed out |
1059 ms |
162576 KB |
Time limit exceeded |
21 |
Execution timed out |
1057 ms |
212532 KB |
Time limit exceeded |
22 |
Execution timed out |
1081 ms |
164888 KB |
Time limit exceeded |
23 |
Execution timed out |
1080 ms |
40568 KB |
Time limit exceeded |
24 |
Execution timed out |
1067 ms |
45364 KB |
Time limit exceeded |
25 |
Execution timed out |
1080 ms |
43640 KB |
Time limit exceeded |
26 |
Execution timed out |
1055 ms |
112084 KB |
Time limit exceeded |
27 |
Execution timed out |
1092 ms |
162188 KB |
Time limit exceeded |
28 |
Execution timed out |
1088 ms |
71668 KB |
Time limit exceeded |
29 |
Execution timed out |
1077 ms |
75240 KB |
Time limit exceeded |
30 |
Execution timed out |
1085 ms |
59000 KB |
Time limit exceeded |
31 |
Execution timed out |
1069 ms |
62968 KB |
Time limit exceeded |
32 |
Execution timed out |
1066 ms |
64876 KB |
Time limit exceeded |
33 |
Execution timed out |
1089 ms |
45436 KB |
Time limit exceeded |
34 |
Execution timed out |
1087 ms |
63224 KB |
Time limit exceeded |
35 |
Execution timed out |
1078 ms |
49656 KB |
Time limit exceeded |
36 |
Execution timed out |
1090 ms |
60152 KB |
Time limit exceeded |
37 |
Execution timed out |
1084 ms |
40312 KB |
Time limit exceeded |
38 |
Execution timed out |
1081 ms |
151800 KB |
Time limit exceeded |
39 |
Execution timed out |
1090 ms |
45048 KB |
Time limit exceeded |
40 |
Execution timed out |
1091 ms |
81144 KB |
Time limit exceeded |
41 |
Execution timed out |
1071 ms |
75640 KB |
Time limit exceeded |
42 |
Execution timed out |
1095 ms |
212596 KB |
Time limit exceeded |