Submission #66180

# Submission time Handle Problem Language Result Execution time Memory
66180 2018-08-10T01:17:35 Z MatheusLealV Brunhilda’s Birthday (BOI13_brunhilda) C++17
100 / 100
302 ms 41132 KB
#include <bits/stdc++.h>
#define N 100050
using namespace std;

int n, q, p[N], dp[10000005], prox[10000005];

int solve(int x)
{
	if(!x) return 0;

	if(dp[x] != -1) return dp[x];

	int ans = -2000000000, opt = 0;

	for(int i = n; i >= (q == 1 ? 1 : max(1, n - 500)); i--)
	{
		if(x % p[i] == 0) continue;

		if(x % p[i] > ans)
		{
			ans = x % p[i];

			opt = i;
		}
	}

	return dp[x] = opt ? solve(x - ans) + 1: 2000000000;
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);

	cin>>n>>q;

	for(int i = 1; i <= n; i++) cin>>p[i];

	sort(p + 1, p + n + 1);

	memset(dp, -1, sizeof dp);

	for(int i = 1, x; i <= q; i++)
	{
		cin>>x;

		int s = solve(x);

		if(s >= 2000000000) cout<<"oo\n";

		else cout<<s<<"\n";

		//print(x);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 35 ms 39416 KB Output is correct
2 Correct 31 ms 39652 KB Output is correct
3 Correct 31 ms 39652 KB Output is correct
4 Correct 36 ms 39652 KB Output is correct
5 Correct 36 ms 39732 KB Output is correct
6 Correct 32 ms 39764 KB Output is correct
7 Correct 31 ms 39764 KB Output is correct
8 Correct 31 ms 39764 KB Output is correct
9 Correct 31 ms 39764 KB Output is correct
10 Correct 32 ms 39764 KB Output is correct
11 Correct 32 ms 39764 KB Output is correct
12 Correct 32 ms 39764 KB Output is correct
13 Correct 40 ms 39764 KB Output is correct
14 Correct 49 ms 39764 KB Output is correct
15 Correct 29 ms 39764 KB Output is correct
16 Correct 31 ms 39764 KB Output is correct
17 Correct 38 ms 39764 KB Output is correct
18 Correct 40 ms 39768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 39780 KB Output is correct
2 Correct 43 ms 40036 KB Output is correct
3 Correct 40 ms 40040 KB Output is correct
4 Correct 34 ms 40040 KB Output is correct
5 Correct 44 ms 40040 KB Output is correct
6 Correct 33 ms 40040 KB Output is correct
7 Correct 32 ms 40040 KB Output is correct
8 Correct 32 ms 40040 KB Output is correct
9 Correct 42 ms 40068 KB Output is correct
10 Correct 41 ms 40068 KB Output is correct
11 Correct 40 ms 40068 KB Output is correct
12 Correct 34 ms 40068 KB Output is correct
13 Correct 35 ms 40068 KB Output is correct
14 Correct 34 ms 40068 KB Output is correct
15 Correct 39 ms 40068 KB Output is correct
16 Correct 48 ms 40156 KB Output is correct
17 Correct 37 ms 40156 KB Output is correct
18 Correct 49 ms 40172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 143 ms 40172 KB Output is correct
2 Correct 106 ms 40172 KB Output is correct
3 Correct 165 ms 40172 KB Output is correct
4 Correct 270 ms 40172 KB Output is correct
5 Correct 257 ms 40500 KB Output is correct
6 Correct 299 ms 40500 KB Output is correct
7 Correct 165 ms 40516 KB Output is correct
8 Correct 133 ms 40516 KB Output is correct
9 Correct 138 ms 40516 KB Output is correct
10 Correct 101 ms 40516 KB Output is correct
11 Correct 118 ms 40516 KB Output is correct
12 Correct 115 ms 40516 KB Output is correct
13 Correct 222 ms 40516 KB Output is correct
14 Correct 88 ms 41132 KB Output is correct
15 Correct 135 ms 41132 KB Output is correct
16 Correct 136 ms 41132 KB Output is correct
17 Correct 77 ms 41132 KB Output is correct
18 Correct 117 ms 41132 KB Output is correct
19 Correct 95 ms 41132 KB Output is correct
20 Correct 147 ms 41132 KB Output is correct
21 Correct 121 ms 41132 KB Output is correct
22 Correct 284 ms 41132 KB Output is correct
23 Correct 292 ms 41132 KB Output is correct
24 Correct 250 ms 41132 KB Output is correct
25 Correct 283 ms 41132 KB Output is correct
26 Correct 251 ms 41132 KB Output is correct
27 Correct 170 ms 41132 KB Output is correct
28 Correct 261 ms 41132 KB Output is correct
29 Correct 282 ms 41132 KB Output is correct
30 Correct 297 ms 41132 KB Output is correct
31 Correct 263 ms 41132 KB Output is correct
32 Correct 275 ms 41132 KB Output is correct
33 Correct 251 ms 41132 KB Output is correct
34 Correct 172 ms 41132 KB Output is correct
35 Correct 266 ms 41132 KB Output is correct
36 Correct 280 ms 41132 KB Output is correct
37 Correct 277 ms 41132 KB Output is correct
38 Correct 281 ms 41132 KB Output is correct
39 Correct 302 ms 41132 KB Output is correct
40 Correct 262 ms 41132 KB Output is correct
41 Correct 171 ms 41132 KB Output is correct
42 Correct 269 ms 41132 KB Output is correct