답안 #66179

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66179 2018-08-10T01:15:55 Z MatheusLealV Brunhilda’s Birthday (BOI13_brunhilda) C++17
97.7778 / 100
441 ms 42564 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(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);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 39620 KB Output is correct
2 Correct 31 ms 39680 KB Output is correct
3 Correct 30 ms 39680 KB Output is correct
4 Correct 37 ms 39804 KB Output is correct
5 Correct 32 ms 39804 KB Output is correct
6 Correct 34 ms 39804 KB Output is correct
7 Correct 31 ms 39804 KB Output is correct
8 Correct 31 ms 39804 KB Output is correct
9 Correct 37 ms 39804 KB Output is correct
10 Correct 30 ms 39804 KB Output is correct
11 Correct 30 ms 39804 KB Output is correct
12 Correct 34 ms 39804 KB Output is correct
13 Correct 35 ms 39804 KB Output is correct
14 Correct 55 ms 39888 KB Output is correct
15 Correct 33 ms 39888 KB Output is correct
16 Correct 35 ms 39888 KB Output is correct
17 Correct 34 ms 39888 KB Output is correct
18 Correct 41 ms 39888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 39888 KB Output is correct
2 Correct 45 ms 40092 KB Output is correct
3 Correct 43 ms 40100 KB Output is correct
4 Correct 32 ms 40100 KB Output is correct
5 Correct 39 ms 40100 KB Output is correct
6 Correct 31 ms 40100 KB Output is correct
7 Correct 33 ms 40100 KB Output is correct
8 Correct 33 ms 40100 KB Output is correct
9 Correct 39 ms 40188 KB Output is correct
10 Correct 43 ms 40188 KB Output is correct
11 Incorrect 36 ms 40188 KB Output isn't correct
12 Correct 30 ms 40188 KB Output is correct
13 Correct 30 ms 40188 KB Output is correct
14 Correct 31 ms 40188 KB Output is correct
15 Correct 40 ms 40188 KB Output is correct
16 Correct 45 ms 40188 KB Output is correct
17 Correct 32 ms 40188 KB Output is correct
18 Incorrect 49 ms 40192 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 154 ms 40320 KB Output is correct
2 Correct 127 ms 40556 KB Output is correct
3 Correct 173 ms 40976 KB Output is correct
4 Correct 288 ms 41132 KB Output is correct
5 Correct 329 ms 41856 KB Output is correct
6 Correct 309 ms 41856 KB Output is correct
7 Correct 176 ms 41856 KB Output is correct
8 Correct 147 ms 41856 KB Output is correct
9 Correct 149 ms 41856 KB Output is correct
10 Correct 111 ms 41856 KB Output is correct
11 Correct 126 ms 41856 KB Output is correct
12 Correct 136 ms 41856 KB Output is correct
13 Correct 237 ms 41856 KB Output is correct
14 Correct 110 ms 42564 KB Output is correct
15 Correct 132 ms 42564 KB Output is correct
16 Correct 140 ms 42564 KB Output is correct
17 Correct 82 ms 42564 KB Output is correct
18 Correct 120 ms 42564 KB Output is correct
19 Correct 105 ms 42564 KB Output is correct
20 Correct 175 ms 42564 KB Output is correct
21 Correct 114 ms 42564 KB Output is correct
22 Correct 289 ms 42564 KB Output is correct
23 Correct 301 ms 42564 KB Output is correct
24 Correct 274 ms 42564 KB Output is correct
25 Correct 304 ms 42564 KB Output is correct
26 Correct 275 ms 42564 KB Output is correct
27 Correct 168 ms 42564 KB Output is correct
28 Correct 257 ms 42564 KB Output is correct
29 Correct 300 ms 42564 KB Output is correct
30 Correct 360 ms 42564 KB Output is correct
31 Correct 297 ms 42564 KB Output is correct
32 Correct 307 ms 42564 KB Output is correct
33 Correct 301 ms 42564 KB Output is correct
34 Correct 187 ms 42564 KB Output is correct
35 Correct 291 ms 42564 KB Output is correct
36 Correct 313 ms 42564 KB Output is correct
37 Correct 298 ms 42564 KB Output is correct
38 Correct 347 ms 42564 KB Output is correct
39 Correct 441 ms 42564 KB Output is correct
40 Correct 315 ms 42564 KB Output is correct
41 Correct 184 ms 42564 KB Output is correct
42 Correct 272 ms 42564 KB Output is correct