Submission #41172

# Submission time Handle Problem Language Result Execution time Memory
41172 2018-02-13T10:11:51 Z ssnsarang2023 Bali Sculptures (APIO15_sculpture) C++14
100 / 100
200 ms 2372 KB
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int oo = (int)1e9+7;
int n, lo, hi, f2[2005], f1[105][105];
ll sum[2005], a[2005];

int dp1(int i, int j, const ll &res, const int &lvl) {
	if (i == n + 1) return j == 0;
	if (f1[i][j] != -1) return f1[i][j];
	f1[i][j] = 0;
	for (int k = i + 1; k <= n + 1; ++k) {
		ll val = sum[i] - sum[k], tmp = ((val >> (ll)(lvl + 1)) << (ll)(lvl + 1));
		if ((res | tmp) == res && !((val >> (ll)lvl) & 1ll))
			f1[i][j] |= dp1(k, j - 1, res, lvl);
	}
	return f1[i][j];
}

int dp2(int i, const ll &res, const int &lvl) {
	if (i == n + 1) return hi + 1;
	if (f2[i] < oo) return f2[i];
	f2[i] = 0;
	for (int j = i + 1; j <= n + 1; ++j) {
		ll val = sum[i] - sum[j], tmp = ((val >> (ll)(lvl + 1)) << (ll)(lvl + 1));
		if ((res | tmp) == res && !((val >> (ll)lvl) & 1ll))
			f2[i] = max(f2[i], dp2(j, res, lvl) - 1);
	}
	return f2[i];
}

int main() {
	scanf("%d%d%d", &n, &lo, &hi);
	for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
	for (int i = n; i >= 1; --i) sum[i] = sum[i + 1] + a[i];
	ll res = 0;
	if (lo != 1) {
		for (int i = 36; i >= 0; --i) {
			memset(f1, -1, sizeof(f1));
			bool ok = false;
			for (int j = lo; j <= hi; ++j) if (dp1(1, j, res, i) == 1)
			{ ok = true; break; }
			if (!ok) res |= (1ll << (ll)i);
		}
	} else {
		for (int i = 40; i >= 0; --i) {
			fill(f2, f2 + n + 1, oo);
			int tmp = dp2(1, res, i);
			if (tmp < 1 || tmp >= oo) res |= (1ll << (ll)i);
		}
	}
	printf("%lld", res);
	return 0;
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:40:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &n, &lo, &hi);
                               ^
sculpture.cpp:41:51: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
                                                   ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 2 ms 608 KB Output is correct
10 Correct 2 ms 616 KB Output is correct
11 Correct 2 ms 704 KB Output is correct
12 Correct 2 ms 744 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 2 ms 752 KB Output is correct
15 Correct 2 ms 776 KB Output is correct
16 Correct 2 ms 776 KB Output is correct
17 Correct 2 ms 852 KB Output is correct
18 Correct 2 ms 856 KB Output is correct
19 Correct 2 ms 856 KB Output is correct
20 Correct 2 ms 856 KB Output is correct
21 Correct 2 ms 856 KB Output is correct
22 Correct 2 ms 856 KB Output is correct
23 Correct 3 ms 856 KB Output is correct
24 Correct 2 ms 856 KB Output is correct
25 Correct 2 ms 856 KB Output is correct
26 Correct 3 ms 856 KB Output is correct
27 Correct 2 ms 856 KB Output is correct
28 Correct 2 ms 856 KB Output is correct
29 Correct 2 ms 856 KB Output is correct
30 Correct 2 ms 856 KB Output is correct
31 Correct 2 ms 856 KB Output is correct
32 Correct 2 ms 856 KB Output is correct
33 Correct 2 ms 856 KB Output is correct
34 Correct 2 ms 856 KB Output is correct
35 Correct 1 ms 856 KB Output is correct
36 Correct 1 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 864 KB Output is correct
2 Correct 1 ms 868 KB Output is correct
3 Correct 2 ms 868 KB Output is correct
4 Correct 1 ms 876 KB Output is correct
5 Correct 2 ms 876 KB Output is correct
6 Correct 2 ms 884 KB Output is correct
7 Correct 1 ms 888 KB Output is correct
8 Correct 1 ms 892 KB Output is correct
9 Correct 2 ms 896 KB Output is correct
10 Correct 1 ms 900 KB Output is correct
11 Correct 2 ms 904 KB Output is correct
12 Correct 2 ms 908 KB Output is correct
13 Correct 1 ms 912 KB Output is correct
14 Correct 2 ms 916 KB Output is correct
15 Correct 2 ms 920 KB Output is correct
16 Correct 1 ms 924 KB Output is correct
17 Correct 2 ms 932 KB Output is correct
18 Correct 2 ms 932 KB Output is correct
19 Correct 2 ms 940 KB Output is correct
20 Correct 2 ms 944 KB Output is correct
21 Correct 2 ms 944 KB Output is correct
22 Correct 2 ms 952 KB Output is correct
23 Correct 2 ms 956 KB Output is correct
24 Correct 2 ms 984 KB Output is correct
25 Correct 2 ms 984 KB Output is correct
26 Correct 2 ms 984 KB Output is correct
27 Correct 2 ms 984 KB Output is correct
28 Correct 2 ms 984 KB Output is correct
29 Correct 2 ms 984 KB Output is correct
30 Correct 2 ms 1104 KB Output is correct
31 Correct 2 ms 1104 KB Output is correct
32 Correct 2 ms 1104 KB Output is correct
33 Correct 2 ms 1104 KB Output is correct
34 Correct 2 ms 1104 KB Output is correct
35 Correct 2 ms 1104 KB Output is correct
36 Correct 2 ms 1104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1104 KB Output is correct
2 Correct 1 ms 1104 KB Output is correct
3 Correct 2 ms 1104 KB Output is correct
4 Correct 2 ms 1104 KB Output is correct
5 Correct 2 ms 1104 KB Output is correct
6 Correct 1 ms 1104 KB Output is correct
7 Correct 1 ms 1160 KB Output is correct
8 Correct 1 ms 1160 KB Output is correct
9 Correct 2 ms 1160 KB Output is correct
10 Correct 2 ms 1160 KB Output is correct
11 Correct 2 ms 1160 KB Output is correct
12 Correct 1 ms 1160 KB Output is correct
13 Correct 1 ms 1160 KB Output is correct
14 Correct 1 ms 1160 KB Output is correct
15 Correct 2 ms 1160 KB Output is correct
16 Correct 2 ms 1160 KB Output is correct
17 Correct 2 ms 1160 KB Output is correct
18 Correct 2 ms 1160 KB Output is correct
19 Correct 2 ms 1160 KB Output is correct
20 Correct 2 ms 1160 KB Output is correct
21 Correct 2 ms 1160 KB Output is correct
22 Correct 2 ms 1160 KB Output is correct
23 Correct 2 ms 1160 KB Output is correct
24 Correct 2 ms 1160 KB Output is correct
25 Correct 2 ms 1160 KB Output is correct
26 Correct 2 ms 1244 KB Output is correct
27 Correct 2 ms 1244 KB Output is correct
28 Correct 3 ms 1244 KB Output is correct
29 Correct 3 ms 1244 KB Output is correct
30 Correct 4 ms 1244 KB Output is correct
31 Correct 2 ms 1244 KB Output is correct
32 Correct 2 ms 1244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1244 KB Output is correct
2 Correct 2 ms 1244 KB Output is correct
3 Correct 1 ms 1244 KB Output is correct
4 Correct 1 ms 1244 KB Output is correct
5 Correct 2 ms 1244 KB Output is correct
6 Correct 2 ms 1244 KB Output is correct
7 Correct 2 ms 1244 KB Output is correct
8 Correct 2 ms 1244 KB Output is correct
9 Correct 2 ms 1244 KB Output is correct
10 Correct 1 ms 1244 KB Output is correct
11 Correct 1 ms 1244 KB Output is correct
12 Correct 2 ms 1256 KB Output is correct
13 Correct 2 ms 1264 KB Output is correct
14 Correct 2 ms 1268 KB Output is correct
15 Correct 2 ms 1272 KB Output is correct
16 Correct 2 ms 1276 KB Output is correct
17 Correct 2 ms 1280 KB Output is correct
18 Correct 2 ms 1284 KB Output is correct
19 Correct 2 ms 1372 KB Output is correct
20 Correct 2 ms 1372 KB Output is correct
21 Correct 2 ms 1372 KB Output is correct
22 Correct 2 ms 1372 KB Output is correct
23 Correct 2 ms 1372 KB Output is correct
24 Correct 2 ms 1372 KB Output is correct
25 Correct 2 ms 1372 KB Output is correct
26 Correct 2 ms 1392 KB Output is correct
27 Correct 2 ms 1392 KB Output is correct
28 Correct 2 ms 1392 KB Output is correct
29 Correct 1 ms 1392 KB Output is correct
30 Correct 1 ms 1392 KB Output is correct
31 Correct 2 ms 1392 KB Output is correct
32 Correct 1 ms 1392 KB Output is correct
33 Correct 1 ms 1392 KB Output is correct
34 Correct 1 ms 1392 KB Output is correct
35 Correct 1 ms 1392 KB Output is correct
36 Correct 2 ms 1392 KB Output is correct
37 Correct 2 ms 1396 KB Output is correct
38 Correct 1 ms 1396 KB Output is correct
39 Correct 2 ms 1404 KB Output is correct
40 Correct 2 ms 1408 KB Output is correct
41 Correct 2 ms 1412 KB Output is correct
42 Correct 2 ms 1416 KB Output is correct
43 Correct 2 ms 1416 KB Output is correct
44 Correct 2 ms 1456 KB Output is correct
45 Correct 2 ms 1460 KB Output is correct
46 Correct 2 ms 1464 KB Output is correct
47 Correct 2 ms 1468 KB Output is correct
48 Correct 2 ms 1472 KB Output is correct
49 Correct 3 ms 1476 KB Output is correct
50 Correct 3 ms 1484 KB Output is correct
51 Correct 2 ms 1484 KB Output is correct
52 Correct 3 ms 1488 KB Output is correct
53 Correct 3 ms 1492 KB Output is correct
54 Correct 2 ms 1496 KB Output is correct
55 Correct 3 ms 1500 KB Output is correct
56 Correct 2 ms 1504 KB Output is correct
57 Correct 2 ms 1508 KB Output is correct
58 Correct 2 ms 1512 KB Output is correct
59 Correct 2 ms 1516 KB Output is correct
60 Correct 2 ms 1520 KB Output is correct
61 Correct 2 ms 1524 KB Output is correct
62 Correct 2 ms 1532 KB Output is correct
63 Correct 2 ms 1536 KB Output is correct
64 Correct 34 ms 1584 KB Output is correct
65 Correct 3 ms 1584 KB Output is correct
66 Correct 5 ms 1584 KB Output is correct
67 Correct 8 ms 1680 KB Output is correct
68 Correct 10 ms 1680 KB Output is correct
69 Correct 8 ms 1776 KB Output is correct
70 Correct 15 ms 1776 KB Output is correct
71 Correct 10 ms 1776 KB Output is correct
72 Correct 19 ms 1776 KB Output is correct
73 Correct 13 ms 1776 KB Output is correct
74 Correct 15 ms 1776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1776 KB Output is correct
2 Correct 1 ms 1776 KB Output is correct
3 Correct 1 ms 1776 KB Output is correct
4 Correct 1 ms 1776 KB Output is correct
5 Correct 2 ms 1776 KB Output is correct
6 Correct 2 ms 1776 KB Output is correct
7 Correct 1 ms 1776 KB Output is correct
8 Correct 1 ms 1776 KB Output is correct
9 Correct 1 ms 1776 KB Output is correct
10 Correct 2 ms 1776 KB Output is correct
11 Correct 2 ms 1776 KB Output is correct
12 Correct 2 ms 1776 KB Output is correct
13 Correct 2 ms 1776 KB Output is correct
14 Correct 1 ms 1776 KB Output is correct
15 Correct 2 ms 1776 KB Output is correct
16 Correct 2 ms 1776 KB Output is correct
17 Correct 2 ms 1776 KB Output is correct
18 Correct 2 ms 1776 KB Output is correct
19 Correct 2 ms 1776 KB Output is correct
20 Correct 2 ms 1776 KB Output is correct
21 Correct 2 ms 1776 KB Output is correct
22 Correct 1 ms 1776 KB Output is correct
23 Correct 2 ms 1776 KB Output is correct
24 Correct 2 ms 1776 KB Output is correct
25 Correct 2 ms 1776 KB Output is correct
26 Correct 2 ms 1776 KB Output is correct
27 Correct 2 ms 1776 KB Output is correct
28 Correct 2 ms 1776 KB Output is correct
29 Correct 2 ms 1776 KB Output is correct
30 Correct 2 ms 1776 KB Output is correct
31 Correct 2 ms 1776 KB Output is correct
32 Correct 2 ms 1776 KB Output is correct
33 Correct 2 ms 1776 KB Output is correct
34 Correct 2 ms 1776 KB Output is correct
35 Correct 2 ms 1776 KB Output is correct
36 Correct 2 ms 1776 KB Output is correct
37 Correct 3 ms 1776 KB Output is correct
38 Correct 3 ms 1776 KB Output is correct
39 Correct 3 ms 1776 KB Output is correct
40 Correct 3 ms 1780 KB Output is correct
41 Correct 3 ms 1784 KB Output is correct
42 Correct 3 ms 1788 KB Output is correct
43 Correct 2 ms 1912 KB Output is correct
44 Correct 2 ms 1912 KB Output is correct
45 Correct 2 ms 1912 KB Output is correct
46 Correct 2 ms 1912 KB Output is correct
47 Correct 2 ms 1932 KB Output is correct
48 Correct 2 ms 1932 KB Output is correct
49 Correct 2 ms 1932 KB Output is correct
50 Correct 2 ms 1932 KB Output is correct
51 Correct 2 ms 1932 KB Output is correct
52 Correct 16 ms 1932 KB Output is correct
53 Correct 14 ms 1932 KB Output is correct
54 Correct 55 ms 1932 KB Output is correct
55 Correct 63 ms 1932 KB Output is correct
56 Correct 84 ms 2032 KB Output is correct
57 Correct 81 ms 2056 KB Output is correct
58 Correct 91 ms 2192 KB Output is correct
59 Correct 145 ms 2192 KB Output is correct
60 Correct 96 ms 2372 KB Output is correct
61 Correct 2 ms 2372 KB Output is correct
62 Correct 14 ms 2372 KB Output is correct
63 Correct 60 ms 2372 KB Output is correct
64 Correct 21 ms 2372 KB Output is correct
65 Correct 37 ms 2372 KB Output is correct
66 Correct 56 ms 2372 KB Output is correct
67 Correct 73 ms 2372 KB Output is correct
68 Correct 200 ms 2372 KB Output is correct
69 Correct 67 ms 2372 KB Output is correct