답안 #444921

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
444921 2021-07-15T21:05:03 Z aryan12 Brunhilda’s Birthday (BOI13_brunhilda) C++17
100 / 100
337 ms 81856 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
 
const int N = 1e7 + 1e5;
int dp[N];
 
void Solve() {
	for(int i = 0; i < N; i++) {
		dp[i] = 0;
	}
	int m, q;
	cin >> m >> q;
	int primes[m + 1];
	int lcm = 1;
	for(int i = 1; i <= m; i++) {
		cin >> primes[i];
		lcm *= primes[i];
		lcm = min(lcm, N + 10);
		for(int j = primes[i] - 1; j < N; j += primes[i]) {
			dp[j] = primes[i] - 1;
		}
	}
	for(int i = N - 2; i >= 0; i--) {
		dp[i] = max(dp[i], dp[i + 1] - 1);
	}
	for(int i = 1; i < N; i++) {
		if(i >= lcm) {
			dp[i] = -1;
			continue;
		}
		dp[i] = dp[i - dp[i]] + 1;
	}
	while(q--) {
		int num;
		cin >> num;
		if(dp[num] == -1) {
			cout << "oo\n";
		}
		else {
			cout << dp[num] << "\n";
		}
	}
}
 
int32_t main() {
	auto begin = std::chrono::high_resolution_clock::now();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) {
		Solve();
	}
	auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 79308 KB Output is correct
2 Correct 127 ms 79484 KB Output is correct
3 Correct 118 ms 79360 KB Output is correct
4 Correct 97 ms 79404 KB Output is correct
5 Correct 120 ms 79364 KB Output is correct
6 Correct 105 ms 79380 KB Output is correct
7 Correct 119 ms 79300 KB Output is correct
8 Correct 128 ms 79332 KB Output is correct
9 Correct 147 ms 79260 KB Output is correct
10 Correct 167 ms 79304 KB Output is correct
11 Correct 155 ms 79320 KB Output is correct
12 Correct 95 ms 79300 KB Output is correct
13 Correct 245 ms 79360 KB Output is correct
14 Correct 251 ms 79404 KB Output is correct
15 Correct 139 ms 79356 KB Output is correct
16 Correct 128 ms 79360 KB Output is correct
17 Correct 120 ms 79400 KB Output is correct
18 Correct 96 ms 79348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 79428 KB Output is correct
2 Correct 132 ms 80676 KB Output is correct
3 Correct 293 ms 80372 KB Output is correct
4 Correct 140 ms 79300 KB Output is correct
5 Correct 219 ms 80112 KB Output is correct
6 Correct 119 ms 79264 KB Output is correct
7 Correct 111 ms 79492 KB Output is correct
8 Correct 131 ms 79280 KB Output is correct
9 Correct 247 ms 80404 KB Output is correct
10 Correct 318 ms 80256 KB Output is correct
11 Correct 309 ms 79924 KB Output is correct
12 Correct 180 ms 79300 KB Output is correct
13 Correct 117 ms 79276 KB Output is correct
14 Correct 142 ms 79300 KB Output is correct
15 Correct 254 ms 79856 KB Output is correct
16 Correct 140 ms 80660 KB Output is correct
17 Correct 254 ms 79308 KB Output is correct
18 Correct 259 ms 80824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 265 ms 80392 KB Output is correct
2 Correct 304 ms 80320 KB Output is correct
3 Correct 308 ms 80556 KB Output is correct
4 Correct 208 ms 80256 KB Output is correct
5 Correct 174 ms 81784 KB Output is correct
6 Correct 267 ms 80528 KB Output is correct
7 Correct 233 ms 81392 KB Output is correct
8 Correct 281 ms 80432 KB Output is correct
9 Correct 280 ms 80428 KB Output is correct
10 Correct 200 ms 79444 KB Output is correct
11 Correct 176 ms 79548 KB Output is correct
12 Correct 237 ms 79556 KB Output is correct
13 Correct 306 ms 80732 KB Output is correct
14 Correct 201 ms 80556 KB Output is correct
15 Correct 253 ms 79696 KB Output is correct
16 Correct 272 ms 79684 KB Output is correct
17 Correct 243 ms 80096 KB Output is correct
18 Correct 312 ms 80356 KB Output is correct
19 Correct 120 ms 79632 KB Output is correct
20 Correct 317 ms 80624 KB Output is correct
21 Correct 218 ms 80696 KB Output is correct
22 Correct 331 ms 81732 KB Output is correct
23 Correct 161 ms 80796 KB Output is correct
24 Correct 138 ms 80304 KB Output is correct
25 Correct 225 ms 80548 KB Output is correct
26 Correct 207 ms 80320 KB Output is correct
27 Correct 337 ms 81272 KB Output is correct
28 Correct 139 ms 80380 KB Output is correct
29 Correct 310 ms 81820 KB Output is correct
30 Correct 278 ms 81296 KB Output is correct
31 Correct 162 ms 80284 KB Output is correct
32 Correct 170 ms 80380 KB Output is correct
33 Correct 128 ms 80260 KB Output is correct
34 Correct 226 ms 81476 KB Output is correct
35 Correct 142 ms 80396 KB Output is correct
36 Correct 333 ms 81564 KB Output is correct
37 Correct 181 ms 81856 KB Output is correct
38 Correct 270 ms 80420 KB Output is correct
39 Correct 149 ms 80388 KB Output is correct
40 Correct 235 ms 80488 KB Output is correct
41 Correct 252 ms 81316 KB Output is correct
42 Correct 326 ms 80560 KB Output is correct