답안 #574287

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
574287 2022-06-08T09:41:32 Z 8e7 Uplifting Excursion (BOI22_vault) C++17
0 / 100
254 ms 8916 KB
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 1100005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
const int inf = 1<<30;
int dp[2][maxn];
int main() {
	io
	int m;
	ll L;
	cin >> m >> L;
	vector<ll> a(2*m+1), ex(2*m+1);	
	ll mins = 0, ans = 0;
	for (int i = 0;i < 2*m+1;i++) {
		cin >> a[i];
		if (i == m) ans += a[i], a[i] = 0;
	}
	for (int i = m+1;i < 2*m+1;i++) {
		ll p = min(a[i], L / (i-m));
		ans += p;
		L -= p * (i-m);
		a[i] -= p;

		ex[i] = min(a[i], (ll)3*m);
		ex[2 * m - i] = min(p,(ll)3 * m);
	}
	for (int i = 0;i < 2 * m+1;i++) {
		if (i < m) mins += ex[i] * (i - m);
	}
	for (int i = 0;i < maxn;i++) dp[0][i] = dp[1][i] = -inf;	

	dp[0][-mins] = 0;
	dp[1][-mins] = 0;
	for (int i = 0;i < 2*m+1;i++) {
		ll cnt = 1;
		vector<int> num;
		while (ex[i] >= cnt) {
			num.push_back(cnt);
			ex[i] -= cnt;
			cnt <<= 1;
		}
		if (ex[i] > 0) num.push_back(ex[i]);
		for (int p:num) {
			for (int j = 0;j < maxn;j++) {
				int val = j + p * (i-m);
				int del = i < m ? -p : p;
				if (val >= 0 && val < maxn) dp[1][val] = max(dp[1][val], dp[0][j] + del);
			}
			for (int j = 0;j < maxn;j++) dp[0][j] = dp[1][j];
		}
	}
	if (L - mins >= maxn || L - mins < 0 || dp[0][L - mins] == -inf) cout << "impossible\n";
	else cout << dp[0][L - mins]+ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 8916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 8916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 8908 KB Output is correct
2 Correct 254 ms 8912 KB Output is correct
3 Incorrect 78 ms 8916 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 8908 KB Output is correct
2 Correct 254 ms 8912 KB Output is correct
3 Incorrect 78 ms 8916 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 8908 KB Output is correct
2 Correct 254 ms 8912 KB Output is correct
3 Incorrect 78 ms 8916 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 8916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 8908 KB Output is correct
2 Correct 254 ms 8912 KB Output is correct
3 Incorrect 78 ms 8916 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 8916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 8908 KB Output is correct
2 Correct 254 ms 8912 KB Output is correct
3 Incorrect 78 ms 8916 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 8916 KB Output isn't correct
2 Halted 0 ms 0 KB -