Submission #463893

# Submission time Handle Problem Language Result Execution time Memory
463893 2021-08-12T01:33:56 Z Hamed5001 Bali Sculptures (APIO15_sculpture) C++14
0 / 100
2 ms 332 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int mxN = 2e3+10;
int dp[mxN][mxN];
int N, A, B;
int Y[mxN];
ll msk, ans;

bool check() {
	if (A == 1) {
		vector<int> d(mxN, 1e9);
		queue<int> q;
		q.push(0);
		d[0] = 0;
		while(q.size()) {
			int i = q.front();
			q.pop();
			ll sum = 0;
			for (int j = i+1; j <= N; ++j) {
				sum += Y[j];
				if (d[j] == 1e9 && !(sum & msk)) {
					d[j] = d[i] + 1;
					q.push(j);
				}
			}
		}
		return d[N] <= B;
	}

	for (int i = 0; i <= N; ++i)
		for (int j = 0; j <= N; ++j)
			dp[i][j] = 0;
	dp[0][0] = 1;
	for (int i = 0; i <= N; ++i) {
		for (int cnt = 0; cnt <= N; ++cnt) {
			if (dp[i][cnt]) {
				ll sum = 0;
				for (int j = i+1; j <= N; ++j) {
					sum += Y[j];
					if (!(msk & sum))
						dp[j][cnt+1] = 1;
				}
			}
		}
	}
	for (int i = A; i <= B; ++i) {
		if (dp[N][i])
			return 1;
	}
	return 0;
}

void solve() {
	cin >> N >> A >> B;
	for (int i = 1; i <= N; ++i)
		cin >> Y[i];

	for (int bit = 50; bit >= 0; --bit) {
		msk |= (1LL << bit);
		if (!check()) 
			msk ^= (1LL << bit), ans |= (1LL << bit);
	}
	cout << ans << endl;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	solve();
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:70:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |  freopen("input.txt", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:71:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |  freopen("output.txt", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -