답안 #671600

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
671600 2022-12-13T09:20:53 Z Radin_Zahedi2 Bali Sculptures (APIO15_sculpture) C++17
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
//#pragma gcc optimize("o2")
using namespace std;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)x.size()
#define endl '\n'
const int mod = 1e9 + 7;
const int inf = 2e9 + 5;
const ll linf = 9e18 + 5;


int n, a, b;
const int n = 2e3 + 5;
int arr[n];

void init() {
}

void input() {
	cin >> n >> a >> b;

	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
	}
}

bool check(ll mask) {
	if (n <= 100) {
		bitset<n> dp[n + 1];

		dp[0][0] = true;
		for (int i = 1; i <= n; i++) {
			ll sum = 0;
			for (int j = i; j >= 1; j--) {
				sum += arr[j];

				if ((sum & mask) == sum) {
					dp[i] |= (dp[j - 1] << 1);
				}
			}
		}

		for (int i = a; i <= b; i++) {
			if (dp[n][i]) {
				return true;
			}
		}

		return false;
	}
	else {
		int ans[n + 1];
	
		ans[0] = 0;
		for (int i = 1; i <= n; i++) {
			ans[i] = b + 1;

			ll sum = 0;
			for (int j = i; j >= 1; j--) {
				sum += arr[j];

				if ((sum & mask) == sum) {
					ans[i] = min(ans[i], ans[j - 1] + 1);
				}
			}
		}

		return (ans[n] <= b);
	}
}

void solve() {
	ll mini = (1ll << 50) - 1;

	for (int i = 49; i >= 0; i--) {
		mini ^= (1ll << i);

		if (!check(mini)) {
			mini ^= (1ll << i);
		}
	}

	cout << mini;
}

void output() {
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int number_of_testcases = 1;
	//cin >> number_of_testcases;
	while (number_of_testcases--) {
		init();

		input();

		solve();

		output();
	}

	return 0;
}

Compilation message

sculpture.cpp:18:11: error: conflicting declaration 'const int n'
   18 | const int n = 2e3 + 5;
      |           ^
sculpture.cpp:17:5: note: previous declaration as 'int n'
   17 | int n, a, b;
      |     ^
sculpture.cpp:19:10: error: array bound is not an integer constant before ']' token
   19 | int arr[n];
      |          ^
sculpture.cpp: In function 'void input()':
sculpture.cpp:28:10: error: 'arr' was not declared in this scope
   28 |   cin >> arr[i];
      |          ^~~
sculpture.cpp: In function 'bool check(ll)':
sculpture.cpp:34:11: error: the value of 'n' is not usable in a constant expression
   34 |   bitset<n> dp[n + 1];
      |           ^
sculpture.cpp:17:5: note: 'int n' is not const
   17 | int n, a, b;
      |     ^
sculpture.cpp:34:11: note: in template argument for type 'long unsigned int'
   34 |   bitset<n> dp[n + 1];
      |           ^
sculpture.cpp:36:8: error: invalid types 'int[int]' for array subscript
   36 |   dp[0][0] = true;
      |        ^
sculpture.cpp:40:12: error: 'arr' was not declared in this scope
   40 |     sum += arr[j];
      |            ^~~
sculpture.cpp:49:13: error: invalid types 'int[int]' for array subscript
   49 |    if (dp[n][i]) {
      |             ^
sculpture.cpp:65:12: error: 'arr' was not declared in this scope
   65 |     sum += arr[j];
      |            ^~~