답안 #463893

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
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);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -