Submission #98533

# Submission time Handle Problem Language Result Execution time Memory
98533 2019-02-23T20:56:55 Z tincamatei Bali Sculptures (APIO15_sculpture) C++14
100 / 100
99 ms 512 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 2000;
const int MAX_N2 = 100;

int dp1[1+MAX_N];
bool dp2[1+MAX_N2][1+MAX_N2];
int y[1+MAX_N];

long long dodp1(int n, int lim) {
	long long rez = 0LL;
	for(int l = 41; l >= 0; --l) {
		long long allowedSet = (rez | ((1LL << l) - 1));
		for(int i = 1; i <= n; ++i) {
			long long s = 0LL;
			dp1[i] = n + 1;
			for(int j = i; j > 0; --j) {
				s += y[j];
				if((s | allowedSet) == allowedSet)
					dp1[i] = min(dp1[i], dp1[j - 1] + 1);
			}
		}
		if(dp1[n] > lim)
			rez = (rez | (1LL << l));
	}
	return rez;
}

long long dodp2(int n, int lim1, int lim2) {
	long long rez = 0LL;
	for(int l = 41; l >= 0; --l) {
		long long allowedSet = (rez | ((1LL << l) - 1));
		dp2[0][0] = true;
		for(int i = 1; i <= n; ++i) {
			for(int j = 1; j <= n; ++j) {
				long long s = 0LL;
				dp2[i][j] = false;
				for(int k = j; k > 0; --k) {
					s += y[k];
					if((s | allowedSet) == allowedSet)
						dp2[i][j] |= dp2[i - 1][k - 1];
				}
			}
		}

		bool ok = false;
		for(int i = lim1; i <= lim2; ++i)
			if(dp2[i][n])
				ok = true;

		if(!ok)
			rez = (rez | (1LL << l));
	}
	return rez;
}

int main() {
#ifdef HOME
	FILE *fin = fopen("input.in", "r");
	FILE *fout = fopen("output.out", "w");
#else
	FILE *fin = stdin;
	FILE *fout = stdout;
#endif

	int n, a, b;
	fscanf(fin, "%d%d%d", &n, &a, &b);
	for(int i = 1; i <= n; ++i)
		fscanf(fin, "%d", &y[i]);
	
	if(a == 1)
		fprintf(fout, "%lld", dodp1(n, b));
	else
		fprintf(fout, "%lld", dodp2(n, a, b));

#ifdef HOME
	fclose(fin);
	fclose(fout);
#endif
	return 0;
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:69:8: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  fscanf(fin, "%d%d%d", &n, &a, &b);
  ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:71:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   fscanf(fin, "%d", &y[i]);
   ~~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 256 KB Output is correct
25 Correct 3 ms 368 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 3 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 252 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 428 KB Output is correct
12 Correct 3 ms 396 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 2 ms 356 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 3 ms 256 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 3 ms 256 KB Output is correct
36 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 3 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 256 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 368 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 256 KB Output is correct
27 Correct 3 ms 256 KB Output is correct
28 Correct 3 ms 256 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 3 ms 256 KB Output is correct
14 Correct 3 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 356 KB Output is correct
17 Correct 3 ms 256 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 3 ms 256 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 3 ms 256 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 256 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 256 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 2 ms 256 KB Output is correct
35 Correct 3 ms 256 KB Output is correct
36 Correct 3 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 2 ms 256 KB Output is correct
42 Correct 2 ms 256 KB Output is correct
43 Correct 2 ms 256 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 3 ms 384 KB Output is correct
47 Correct 3 ms 384 KB Output is correct
48 Correct 2 ms 384 KB Output is correct
49 Correct 2 ms 384 KB Output is correct
50 Correct 3 ms 256 KB Output is correct
51 Correct 3 ms 384 KB Output is correct
52 Correct 3 ms 384 KB Output is correct
53 Correct 3 ms 384 KB Output is correct
54 Correct 3 ms 384 KB Output is correct
55 Correct 3 ms 384 KB Output is correct
56 Correct 3 ms 256 KB Output is correct
57 Correct 3 ms 460 KB Output is correct
58 Correct 3 ms 256 KB Output is correct
59 Correct 3 ms 384 KB Output is correct
60 Correct 3 ms 256 KB Output is correct
61 Correct 3 ms 384 KB Output is correct
62 Correct 2 ms 356 KB Output is correct
63 Correct 2 ms 384 KB Output is correct
64 Correct 32 ms 384 KB Output is correct
65 Correct 7 ms 256 KB Output is correct
66 Correct 15 ms 384 KB Output is correct
67 Correct 14 ms 384 KB Output is correct
68 Correct 26 ms 384 KB Output is correct
69 Correct 36 ms 384 KB Output is correct
70 Correct 26 ms 384 KB Output is correct
71 Correct 30 ms 372 KB Output is correct
72 Correct 30 ms 384 KB Output is correct
73 Correct 30 ms 384 KB Output is correct
74 Correct 30 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 256 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 2 ms 400 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 3 ms 384 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 3 ms 384 KB Output is correct
37 Correct 3 ms 384 KB Output is correct
38 Correct 2 ms 256 KB Output is correct
39 Correct 3 ms 256 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 3 ms 256 KB Output is correct
42 Correct 3 ms 384 KB Output is correct
43 Correct 2 ms 256 KB Output is correct
44 Correct 2 ms 256 KB Output is correct
45 Correct 3 ms 384 KB Output is correct
46 Correct 3 ms 384 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 3 ms 384 KB Output is correct
49 Correct 2 ms 256 KB Output is correct
50 Correct 3 ms 256 KB Output is correct
51 Correct 3 ms 384 KB Output is correct
52 Correct 12 ms 412 KB Output is correct
53 Correct 16 ms 384 KB Output is correct
54 Correct 25 ms 384 KB Output is correct
55 Correct 26 ms 384 KB Output is correct
56 Correct 83 ms 384 KB Output is correct
57 Correct 84 ms 384 KB Output is correct
58 Correct 81 ms 392 KB Output is correct
59 Correct 79 ms 384 KB Output is correct
60 Correct 89 ms 504 KB Output is correct
61 Correct 3 ms 356 KB Output is correct
62 Correct 17 ms 384 KB Output is correct
63 Correct 27 ms 384 KB Output is correct
64 Correct 23 ms 384 KB Output is correct
65 Correct 43 ms 384 KB Output is correct
66 Correct 63 ms 384 KB Output is correct
67 Correct 94 ms 504 KB Output is correct
68 Correct 99 ms 392 KB Output is correct
69 Correct 81 ms 384 KB Output is correct