Submission #66177

# Submission time Handle Problem Language Result Execution time Memory
66177 2018-08-10T01:13:46 Z MatheusLealV Brunhilda’s Birthday (BOI13_brunhilda) C++17
74.6032 / 100
599 ms 84488 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 >= max(0, n - 1000); 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 Runtime error 78 ms 78840 KB Execution killed with signal 8 (could be triggered by violating memory limits)
2 Runtime error 89 ms 78972 KB Execution killed with signal 8 (could be triggered by violating memory limits)
3 Runtime error 89 ms 78972 KB Execution killed with signal 8 (could be triggered by violating memory limits)
4 Runtime error 92 ms 79160 KB Execution killed with signal 8 (could be triggered by violating memory limits)
5 Runtime error 92 ms 79164 KB Execution killed with signal 8 (could be triggered by violating memory limits)
6 Runtime error 77 ms 79276 KB Execution killed with signal 8 (could be triggered by violating memory limits)
7 Runtime error 86 ms 79276 KB Execution killed with signal 8 (could be triggered by violating memory limits)
8 Runtime error 77 ms 79276 KB Execution killed with signal 8 (could be triggered by violating memory limits)
9 Runtime error 75 ms 79276 KB Execution killed with signal 8 (could be triggered by violating memory limits)
10 Runtime error 82 ms 79276 KB Execution killed with signal 8 (could be triggered by violating memory limits)
11 Runtime error 79 ms 79276 KB Execution killed with signal 8 (could be triggered by violating memory limits)
12 Runtime error 78 ms 79356 KB Execution killed with signal 8 (could be triggered by violating memory limits)
13 Runtime error 79 ms 79356 KB Execution killed with signal 8 (could be triggered by violating memory limits)
14 Correct 67 ms 79356 KB Output is correct
15 Runtime error 82 ms 79356 KB Execution killed with signal 8 (could be triggered by violating memory limits)
16 Runtime error 79 ms 79388 KB Execution killed with signal 8 (could be triggered by violating memory limits)
17 Runtime error 77 ms 79388 KB Execution killed with signal 8 (could be triggered by violating memory limits)
18 Runtime error 86 ms 79388 KB Execution killed with signal 8 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 31 ms 79388 KB Output is correct
2 Correct 41 ms 79596 KB Output is correct
3 Correct 40 ms 79596 KB Output is correct
4 Correct 36 ms 79596 KB Output is correct
5 Correct 39 ms 79612 KB Output is correct
6 Correct 33 ms 79612 KB Output is correct
7 Correct 38 ms 79612 KB Output is correct
8 Runtime error 87 ms 79612 KB Execution killed with signal 8 (could be triggered by violating memory limits)
9 Correct 44 ms 79700 KB Output is correct
10 Correct 42 ms 79700 KB Output is correct
11 Incorrect 38 ms 79700 KB Output isn't correct
12 Correct 32 ms 79700 KB Output is correct
13 Correct 41 ms 79700 KB Output is correct
14 Correct 31 ms 79700 KB Output is correct
15 Correct 38 ms 79700 KB Output is correct
16 Correct 40 ms 79700 KB Output is correct
17 Correct 38 ms 79700 KB Output is correct
18 Correct 46 ms 79828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 263 ms 80056 KB Output is correct
2 Correct 206 ms 80092 KB Output is correct
3 Correct 311 ms 80388 KB Output is correct
4 Correct 480 ms 80388 KB Output is correct
5 Correct 490 ms 80720 KB Output is correct
6 Correct 593 ms 80776 KB Output is correct
7 Correct 293 ms 81020 KB Output is correct
8 Correct 263 ms 81020 KB Output is correct
9 Correct 247 ms 81020 KB Output is correct
10 Correct 162 ms 81020 KB Output is correct
11 Correct 211 ms 81112 KB Output is correct
12 Correct 206 ms 81112 KB Output is correct
13 Correct 464 ms 81648 KB Output is correct
14 Runtime error 81 ms 81648 KB Execution killed with signal 8 (could be triggered by violating memory limits)
15 Correct 246 ms 81648 KB Output is correct
16 Correct 253 ms 81648 KB Output is correct
17 Correct 166 ms 81648 KB Output is correct
18 Correct 195 ms 81716 KB Output is correct
19 Correct 182 ms 81716 KB Output is correct
20 Correct 288 ms 82068 KB Output is correct
21 Runtime error 82 ms 82068 KB Execution killed with signal 8 (could be triggered by violating memory limits)
22 Correct 541 ms 82552 KB Output is correct
23 Correct 565 ms 82552 KB Output is correct
24 Correct 543 ms 82552 KB Output is correct
25 Correct 556 ms 82552 KB Output is correct
26 Correct 599 ms 82620 KB Output is correct
27 Correct 296 ms 82940 KB Output is correct
28 Runtime error 91 ms 82940 KB Execution killed with signal 8 (could be triggered by violating memory limits)
29 Correct 557 ms 83172 KB Output is correct
30 Correct 537 ms 83392 KB Output is correct
31 Correct 459 ms 83392 KB Output is correct
32 Correct 498 ms 83392 KB Output is correct
33 Correct 484 ms 83448 KB Output is correct
34 Correct 299 ms 83576 KB Output is correct
35 Correct 470 ms 83576 KB Output is correct
36 Correct 521 ms 84004 KB Output is correct
37 Correct 519 ms 84120 KB Output is correct
38 Correct 595 ms 84120 KB Output is correct
39 Correct 559 ms 84120 KB Output is correct
40 Correct 568 ms 84344 KB Output is correct
41 Correct 323 ms 84488 KB Output is correct
42 Correct 560 ms 84488 KB Output is correct