Submission #631368

# Submission time Handle Problem Language Result Execution time Memory
631368 2022-08-18T03:52:15 Z uylulu Brunhilda’s Birthday (BOI13_brunhilda) C++14
93.1746 / 100
400 ms 79116 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define endl "\n"

const int N = 1e7,len = 1e5;

int mx[N + 1],dp[N + 1],num[len + 1];
int m,q,lim;

int lcm(int a,int b) {
	return a*b/(__gcd(a,b));
}

void init() {
	lim = num[1];
	for(int i = 2;i <= m;i++) {
		if(lim > N) break;
		lim = lcm(lim,num[i]);
	}
	for(int i = 1;i <= m;i++) {
		for(int j = 1;num[i]*j <= N;j++) {
			mx[num[i]*j] = max(num[i],mx[num[i]*j]);
		}
	}
	dp[0] = 0;
	for(int i = 1;i < num[m];i++) {
		dp[i] = 1;
	}
	int lst = 0,temp = 0;
	for(int i = 1;i < num[m];i++) {
		if(temp < (mx[i] - 1) - (num[m] - i)) {
			temp = (mx[i] - 1) - (num[m] - i);
			lst = i;
		}
	}
	for(int i = num[m];i < min(lim,N);i++) {
		while(mx[lst] - 1 < (i - lst)) lst++;
		dp[i] = dp[lst] + 1;
	}
}

signed main() {
	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);

	cin>>m>>q;
	for(int i = 1;i <= m;i++) cin>>num[i];
	init();
	while(q--) {
		int x;
		cin>>x;
		if(x >= lim) {
			cout<<"oo"<<endl;
		} else {
			cout<<dp[x]<<endl;
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 31 ms 39372 KB Output is correct
2 Correct 78 ms 78468 KB Output is correct
3 Correct 43 ms 40448 KB Output is correct
4 Correct 79 ms 78480 KB Output is correct
5 Correct 78 ms 78476 KB Output is correct
6 Correct 34 ms 39340 KB Output is correct
7 Correct 40 ms 40456 KB Output is correct
8 Correct 45 ms 42880 KB Output is correct
9 Correct 88 ms 78540 KB Output is correct
10 Correct 114 ms 78444 KB Output is correct
11 Correct 112 ms 78456 KB Output is correct
12 Correct 55 ms 78540 KB Output is correct
13 Correct 169 ms 78472 KB Output is correct
14 Correct 176 ms 78540 KB Output is correct
15 Correct 105 ms 78480 KB Output is correct
16 Correct 101 ms 78464 KB Output is correct
17 Correct 87 ms 78580 KB Output is correct
18 Correct 68 ms 78476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 78516 KB Output is correct
2 Correct 103 ms 78836 KB Output is correct
3 Correct 220 ms 78840 KB Output is correct
4 Correct 84 ms 78472 KB Output is correct
5 Correct 187 ms 78796 KB Output is correct
6 Correct 75 ms 78480 KB Output is correct
7 Correct 68 ms 78576 KB Output is correct
8 Correct 79 ms 78520 KB Output is correct
9 Correct 186 ms 78752 KB Output is correct
10 Correct 242 ms 78808 KB Output is correct
11 Correct 228 ms 78668 KB Output is correct
12 Correct 111 ms 78472 KB Output is correct
13 Correct 63 ms 78512 KB Output is correct
14 Correct 87 ms 78464 KB Output is correct
15 Correct 176 ms 78628 KB Output is correct
16 Correct 98 ms 78796 KB Output is correct
17 Correct 170 ms 78568 KB Output is correct
18 Incorrect 197 ms 78912 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 241 ms 78920 KB Output is correct
2 Correct 272 ms 78800 KB Output is correct
3 Correct 310 ms 78920 KB Output is correct
4 Correct 261 ms 78812 KB Output is correct
5 Correct 274 ms 79088 KB Output is correct
6 Correct 306 ms 78792 KB Output is correct
7 Correct 258 ms 79024 KB Output is correct
8 Correct 294 ms 78796 KB Output is correct
9 Correct 247 ms 78768 KB Output is correct
10 Correct 176 ms 78620 KB Output is correct
11 Correct 148 ms 78624 KB Output is correct
12 Correct 203 ms 78720 KB Output is correct
13 Correct 357 ms 78920 KB Output is correct
14 Correct 278 ms 79084 KB Output is correct
15 Correct 208 ms 78608 KB Output is correct
16 Correct 238 ms 78668 KB Output is correct
17 Correct 202 ms 78768 KB Output is correct
18 Correct 326 ms 78800 KB Output is correct
19 Correct 101 ms 78616 KB Output is correct
20 Correct 302 ms 78920 KB Output is correct
21 Incorrect 308 ms 79104 KB Output isn't correct
22 Correct 399 ms 79076 KB Output is correct
23 Correct 255 ms 78828 KB Output is correct
24 Correct 223 ms 78824 KB Output is correct
25 Correct 299 ms 78876 KB Output is correct
26 Correct 255 ms 78732 KB Output is correct
27 Correct 354 ms 78952 KB Output is correct
28 Incorrect 220 ms 78880 KB Output isn't correct
29 Correct 400 ms 79112 KB Output is correct
30 Correct 359 ms 79048 KB Output is correct
31 Correct 242 ms 78760 KB Output is correct
32 Correct 237 ms 78772 KB Output is correct
33 Correct 204 ms 78704 KB Output is correct
34 Correct 248 ms 79116 KB Output is correct
35 Incorrect 238 ms 78840 KB Output isn't correct
36 Correct 385 ms 79104 KB Output is correct
37 Correct 271 ms 79104 KB Output is correct
38 Correct 326 ms 78872 KB Output is correct
39 Correct 267 ms 78820 KB Output is correct
40 Correct 301 ms 78964 KB Output is correct
41 Correct 240 ms 79000 KB Output is correct
42 Incorrect 368 ms 78860 KB Output isn't correct