답안 #400654

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
400654 2021-05-08T13:00:39 Z BERNARB01 Bali Sculptures (APIO15_sculpture) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = (int) 103;
const long long inf = (long long) 4e18;
 
int n, a, b, y[N];
long long dp[N][N][N];
long long Dp[2003][2003];

long long sol0(int i, long long run, int stage, long long sum = 0) {
	if (i == n) {
		if (a <= stage && stage <= b) {
			return run | sum;
		}
		return inf;
	}
	long long ret; //dp[i][stage][run];
	//if (ret != -1) {
		//return ret;
	//}
	sum += y[i];
	ret = sol0(i + 1, run, stage, sum);
	if (stage + 1 <= b && i + 1 < n) {
		ret = min(ret, sol0(i + 1, run | sum, stage + 1));
	}
	return ret;
}

long long sol(int i, int j, int stage, long long sum = 0) {
	if (i == n) {
		if (a <= stage && stage <= b) {
			return sum;
		}
		return inf;
	}
	long long& ret = dp[i][j][stage];
	if (ret != -1) {
		return ret;
	}
	sum += y[i];
	ret = sol(i + 1, j, stage, sum);
	if (stage + 1 <= b && i + 1 < n) {
		ret = min(ret, sum | sol(i + 1, i + 1, stage + 1));
	}
	return ret;
}
 
long long sol2(int i, int stage, int j = 0, long long sum = 0) {
	if (i == n) {
		return (a <= stage && stage <= b ? sum : inf);
	}
	long long& ret = Dp[i][j];
	if (ret != -1) {
		return ret;
	}
	sum += y[i];
	ret = sol2(i + 1, stage, j, sum);
	if (i + 1 < n && stage + 1 <= b) {
		ret = min(ret, sum | sol2(i + 1, stage + 1, i + 1));
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> a >> b;
	for (int i = 0; i < n; i++) {
		cin >> y[i];
	}
	memset(dp, -1, sizeof dp);
	if (n <= 20) {
		cout << sol0(0, 0, 1) << '\n';
	} else if (n <= 100) {
		cout << sol(0, 0, 1) << '\n';
	} else {
		long long sum = 0;
		for (int i = 0; i < n; i++) {
			sum += y[i];
		}
		long long res = sum;
		long long summ = 0;
		for (int i = n - 1; i >= 0; i--) {
			sum -= a[i];
			summ += a[i];
			res = min(res, sum | summ);
		}
		cout << min(res, sol2(0, 1)) << '\n';
	}
	return 0;
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:86:14: error: invalid types 'int[int]' for array subscript
   86 |    sum -= a[i];
      |              ^
sculpture.cpp:87:15: error: invalid types 'int[int]' for array subscript
   87 |    summ += a[i];
      |               ^