Submission #849210

# Submission time Handle Problem Language Result Execution time Memory
849210 2023-09-14T09:18:49 Z vjudge1 Uplifting Excursion (BOI22_vault) C++17
5 / 100
5000 ms 524288 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#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 ll inf = 1e18;
int32_t 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";
		return 0;
	}
	int N = max(-mn ,mx)+2;
	int dp[N*2]={};
	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 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 132 ms 856 KB Output is correct
7 Correct 27 ms 600 KB Output is correct
8 Correct 122 ms 856 KB Output is correct
9 Correct 421 ms 1368 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 132 ms 856 KB Output is correct
7 Correct 27 ms 600 KB Output is correct
8 Correct 122 ms 856 KB Output is correct
9 Correct 421 ms 1368 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 143 ms 1028 KB Output is correct
18 Correct 28 ms 600 KB Output is correct
19 Correct 122 ms 856 KB Output is correct
20 Correct 433 ms 1488 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 600 KB Output is correct
24 Correct 3758 ms 4724 KB Output is correct
25 Correct 564 ms 2252 KB Output is correct
26 Execution timed out 5029 ms 8412 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Runtime error 210 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Runtime error 210 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Runtime error 210 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 132 ms 856 KB Output is correct
7 Correct 27 ms 600 KB Output is correct
8 Correct 122 ms 856 KB Output is correct
9 Correct 421 ms 1368 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Runtime error 210 ms 524288 KB Execution killed with signal 9
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Runtime error 210 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 132 ms 856 KB Output is correct
7 Correct 27 ms 600 KB Output is correct
8 Correct 122 ms 856 KB Output is correct
9 Correct 421 ms 1368 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 143 ms 1028 KB Output is correct
18 Correct 28 ms 600 KB Output is correct
19 Correct 122 ms 856 KB Output is correct
20 Correct 433 ms 1488 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 600 KB Output is correct
24 Correct 3758 ms 4724 KB Output is correct
25 Correct 564 ms 2252 KB Output is correct
26 Execution timed out 5029 ms 8412 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Runtime error 210 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 132 ms 856 KB Output is correct
7 Correct 27 ms 600 KB Output is correct
8 Correct 122 ms 856 KB Output is correct
9 Correct 421 ms 1368 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 143 ms 1028 KB Output is correct
18 Correct 28 ms 600 KB Output is correct
19 Correct 122 ms 856 KB Output is correct
20 Correct 433 ms 1488 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 600 KB Output is correct
24 Correct 3758 ms 4724 KB Output is correct
25 Correct 564 ms 2252 KB Output is correct
26 Execution timed out 5029 ms 8412 KB Time limit exceeded
27 Halted 0 ms 0 KB -