답안 #495932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
495932 2021-12-20T08:08:31 Z ntabc05101 Bali Sculptures (APIO15_sculpture) C++14
100 / 100
142 ms 348 KB
#include<bits/stdc++.h>
using namespace std;

#define taskname ""

const int lgN = 41;

int main() {
	if (fopen(taskname".inp", "r")) {
		freopen(taskname".inp", "r", stdin);
		freopen(taskname".out", "w", stdout);
	}
	else {
		if (fopen(taskname".in", "r")) {
			freopen(taskname".in", "r", stdin);
			freopen(taskname".out", "w", stdout);
		}
	}

	cin.tie(0)->sync_with_stdio(0);

	int n, a, b; cin >> n >> a >> b;
	long long y[n + 1];
	y[0] = 0;
	for (int i = 1; i <= n; i++) {
		cin >> y[i]; y[i] += y[i - 1];
	}

	long long res = 0;
	if (n > 100) {
		pair<bool, int> dp[n + 1];
		for (int x = lgN - 1; ~x; x--) {
			dp[0] = {1, 0};
			for (int i = 1; i <= n; i++) {
				dp[i] = {0, 0};
				for (int j = i - 1; ~j; j--) {
					if ((res >> x) == (((y[i] - y[j]) | res) >> x)) {
						dp[i] = max(dp[i], dp[j]);
					}
				}
				dp[i].second--;
			}
			if (!dp[n].first || -dp[n].second > b) {
				res |= 1ll << x;
			}
		}

		cout << res << "\n";
	}
	else {
		bool dp[n + 1][n + 1];
		for (int x = lgN - 1; ~x; x--) {
			memset(dp, 0, sizeof(dp));
			dp[0][0] = 1;
			for (int i = 1; i <= n; i++) {
				for (int k = i - 1; ~k; k--) {
					if ((res >> x) == (((y[i] - y[k]) | res) >> x)) {
						for (int j = 1; j <= i; j++) {
							dp[i][j] |= dp[k][j - 1];
						}
					}
				}
			}
	
			int chk = 1;
			for (int j = a; j <= b; j++) {
				if (dp[n][j]) {
					chk = 0; break;
				}
			}
			if (chk) {
				res |= 1ll << x;
			}
		}

		cout << res << "\n";
	}

	return 0;
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:10:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |   freopen(taskname".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:11:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |   freopen(taskname".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:15:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |    freopen(taskname".in", "r", stdin);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:16:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |    freopen(taskname".out", "w", stdout);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 2 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 ms 312 KB Output is correct
33 Correct 1 ms 208 KB Output is correct
34 Correct 1 ms 312 KB Output is correct
35 Correct 1 ms 208 KB Output is correct
36 Correct 3 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 2 ms 204 KB Output is correct
32 Correct 2 ms 204 KB Output is correct
33 Correct 2 ms 312 KB Output is correct
34 Correct 2 ms 204 KB Output is correct
35 Correct 2 ms 204 KB Output is correct
36 Correct 2 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 2 ms 280 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 2 ms 204 KB Output is correct
19 Correct 4 ms 204 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 2 ms 204 KB Output is correct
22 Correct 2 ms 204 KB Output is correct
23 Correct 2 ms 204 KB Output is correct
24 Correct 3 ms 204 KB Output is correct
25 Correct 3 ms 204 KB Output is correct
26 Correct 4 ms 204 KB Output is correct
27 Correct 8 ms 320 KB Output is correct
28 Correct 8 ms 204 KB Output is correct
29 Correct 9 ms 320 KB Output is correct
30 Correct 10 ms 204 KB Output is correct
31 Correct 9 ms 320 KB Output is correct
32 Correct 9 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 308 KB Output is correct
30 Correct 1 ms 316 KB Output is correct
31 Correct 1 ms 316 KB Output is correct
32 Correct 1 ms 208 KB Output is correct
33 Correct 1 ms 208 KB Output is correct
34 Correct 1 ms 208 KB Output is correct
35 Correct 1 ms 320 KB Output is correct
36 Correct 1 ms 208 KB Output is correct
37 Correct 1 ms 208 KB Output is correct
38 Correct 4 ms 208 KB Output is correct
39 Correct 1 ms 208 KB Output is correct
40 Correct 1 ms 208 KB Output is correct
41 Correct 2 ms 208 KB Output is correct
42 Correct 3 ms 208 KB Output is correct
43 Correct 2 ms 316 KB Output is correct
44 Correct 5 ms 316 KB Output is correct
45 Correct 2 ms 208 KB Output is correct
46 Correct 2 ms 208 KB Output is correct
47 Correct 2 ms 208 KB Output is correct
48 Correct 3 ms 208 KB Output is correct
49 Correct 5 ms 312 KB Output is correct
50 Correct 7 ms 324 KB Output is correct
51 Correct 11 ms 208 KB Output is correct
52 Correct 8 ms 208 KB Output is correct
53 Correct 9 ms 208 KB Output is correct
54 Correct 20 ms 324 KB Output is correct
55 Correct 9 ms 208 KB Output is correct
56 Correct 3 ms 316 KB Output is correct
57 Correct 2 ms 208 KB Output is correct
58 Correct 2 ms 208 KB Output is correct
59 Correct 4 ms 316 KB Output is correct
60 Correct 2 ms 208 KB Output is correct
61 Correct 3 ms 320 KB Output is correct
62 Correct 4 ms 208 KB Output is correct
63 Correct 4 ms 208 KB Output is correct
64 Correct 7 ms 324 KB Output is correct
65 Correct 2 ms 312 KB Output is correct
66 Correct 1 ms 208 KB Output is correct
67 Correct 2 ms 208 KB Output is correct
68 Correct 2 ms 208 KB Output is correct
69 Correct 10 ms 208 KB Output is correct
70 Correct 2 ms 208 KB Output is correct
71 Correct 4 ms 312 KB Output is correct
72 Correct 4 ms 328 KB Output is correct
73 Correct 3 ms 312 KB Output is correct
74 Correct 3 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 2 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 2 ms 316 KB Output is correct
29 Correct 2 ms 204 KB Output is correct
30 Correct 2 ms 316 KB Output is correct
31 Correct 2 ms 316 KB Output is correct
32 Correct 2 ms 204 KB Output is correct
33 Correct 2 ms 204 KB Output is correct
34 Correct 2 ms 204 KB Output is correct
35 Correct 3 ms 316 KB Output is correct
36 Correct 5 ms 316 KB Output is correct
37 Correct 6 ms 204 KB Output is correct
38 Correct 9 ms 204 KB Output is correct
39 Correct 9 ms 204 KB Output is correct
40 Correct 10 ms 324 KB Output is correct
41 Correct 9 ms 204 KB Output is correct
42 Correct 24 ms 324 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 2 ms 204 KB Output is correct
45 Correct 2 ms 324 KB Output is correct
46 Correct 6 ms 204 KB Output is correct
47 Correct 2 ms 204 KB Output is correct
48 Correct 4 ms 204 KB Output is correct
49 Correct 3 ms 320 KB Output is correct
50 Correct 4 ms 312 KB Output is correct
51 Correct 1 ms 316 KB Output is correct
52 Correct 10 ms 204 KB Output is correct
53 Correct 15 ms 204 KB Output is correct
54 Correct 28 ms 332 KB Output is correct
55 Correct 26 ms 332 KB Output is correct
56 Correct 100 ms 344 KB Output is correct
57 Correct 93 ms 340 KB Output is correct
58 Correct 80 ms 340 KB Output is correct
59 Correct 79 ms 332 KB Output is correct
60 Correct 101 ms 344 KB Output is correct
61 Correct 1 ms 312 KB Output is correct
62 Correct 15 ms 204 KB Output is correct
63 Correct 28 ms 320 KB Output is correct
64 Correct 41 ms 328 KB Output is correct
65 Correct 48 ms 328 KB Output is correct
66 Correct 75 ms 340 KB Output is correct
67 Correct 98 ms 332 KB Output is correct
68 Correct 142 ms 332 KB Output is correct
69 Correct 101 ms 348 KB Output is correct