Submission #849206

# Submission time Handle Problem Language Result Execution time Memory
849206 2023-09-14T09:14:19 Z vjudge1 Uplifting Excursion (BOI22_vault) C++17
0 / 100
78 ms 4700 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define endl '\n'
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
const int mod = 1e9 + 7;
const int N = 1e6 + 15;
const ll inf = 1e18;
int dp[2*N];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n, l;
	cin >> n >> l;
	vector<int> a(2*n + 1);
	vector<int> b;
	for (int i=-n;i<=n;i++){
		cin >> a[i+n];
		int frq = a[i+n];
		for (int j=0;j<frq;j++) b.pb(i);
	}
	int mx = 0, mn=0;
	for (auto it : b) (it >= 0 ? mx+=it : mn+=it);
	if (l > mx || l < mn) {
		cout << "impossible\n";
	}
	dp[N] = 1;// 0
	for (int i=0;i<sz(b);i++){
		if (b[i] >= 0){
			for (int k=2*N-1;k>=b[i];k--){
				if (dp[k-b[i]]) dp[k] = max(dp[k], dp[k-b[i]]+1);
			}
		}
		else {
			b[i] = -b[i];
			for (int k=0;k+b[i]<2*N;k++){
				if (dp[k+b[i]]) dp[k] = max(dp[k], dp[k+b[i]]+1);
			}
		}
	}
	if (dp[N+l]) cout << dp[N+l]-1 << endl;
	else cout << "impossible\n";
}
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2392 KB Output is correct
2 Correct 11 ms 2396 KB Output is correct
3 Correct 8 ms 2516 KB Output is correct
4 Correct 78 ms 2396 KB Output is correct
5 Runtime error 2 ms 4696 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2392 KB Output is correct
2 Correct 11 ms 2396 KB Output is correct
3 Correct 8 ms 2516 KB Output is correct
4 Correct 78 ms 2396 KB Output is correct
5 Runtime error 2 ms 4696 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 77 ms 2496 KB Output is correct
2 Runtime error 3 ms 4700 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 77 ms 2496 KB Output is correct
2 Runtime error 3 ms 4700 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 77 ms 2496 KB Output is correct
2 Runtime error 3 ms 4700 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2392 KB Output is correct
2 Correct 11 ms 2396 KB Output is correct
3 Correct 8 ms 2516 KB Output is correct
4 Correct 78 ms 2396 KB Output is correct
5 Runtime error 2 ms 4696 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 77 ms 2496 KB Output is correct
2 Runtime error 3 ms 4700 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2392 KB Output is correct
2 Correct 11 ms 2396 KB Output is correct
3 Correct 8 ms 2516 KB Output is correct
4 Correct 78 ms 2396 KB Output is correct
5 Runtime error 2 ms 4696 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 77 ms 2496 KB Output is correct
2 Runtime error 3 ms 4700 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2392 KB Output is correct
2 Correct 11 ms 2396 KB Output is correct
3 Correct 8 ms 2516 KB Output is correct
4 Correct 78 ms 2396 KB Output is correct
5 Runtime error 2 ms 4696 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -