Submission #453141

# Submission time Handle Problem Language Result Execution time Memory
453141 2021-08-04T08:17:21 Z nonsensenonsense1 Bali Sculptures (APIO15_sculpture) C++17
0 / 100
1 ms 204 KB
#include <cstdio>
#include <algorithm>

const int LG = 60;
const int N1 = 100;
const int N2 = 2000;
int n, a, b, y[N2], mn[N2 + 1];
bool d[N1 + 1][N1 + 1];

inline bool good(long long s, long long x, int l) 
{
	return ((x | s) & ~(((long long)1 << l) - 1)) == x;
}

bool test1(long long x, int l) 
{
	for (int i = 1; i <= n; ++i) for (int j = 1; j <= i; ++j) {
		d[i][j] = 0;
		long long s = 0;
		for (int k = i - 1; k >= 0; --k) {
			s += y[k];
			if (good(s, x, l)) d[i][j] = d[i][j] || d[k][j - 1];
		}
		if (i == n && j >= a && j <= b && d[i][j]) return true;
	}
	return false;
}

bool test2(long long x, int l) 
{
	for (int i = 1; i <= n; ++i) {
		mn[i] = n + 1;
		long long s = 0;
		for (int j = i - 1; j >= 0; --j) {
			s += y[j];
			if (good(s, x, l)) mn[i] = std::min(mn[i], mn[j] + 1);
		}
	}
	return mn[n] <= b;
}

int main() 
{
	scanf("%d%d%d", &n, &a, &b);
	for (int i = 0; i < n; ++i) scanf("%d", y + i);
	long long ans = 0;
	d[0][0] = 1;
	for (int i = LG - 1; i >= 0; --i) if (a == 1 && test1(ans, i) || a != 1 && !test2(ans, i)) ans |= (long long)1 << i;
	printf("%lld\n", ans);
	return 0;
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:48:47: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   48 |  for (int i = LG - 1; i >= 0; --i) if (a == 1 && test1(ans, i) || a != 1 && !test2(ans, i)) ans |= (long long)1 << i;
      |                                        ~~~~~~~^~~~~~~~~~~~~~~~
sculpture.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |  scanf("%d%d%d", &n, &a, &b);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:45:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |  for (int i = 0; i < n; ++i) scanf("%d", y + i);
      |                              ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -