# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
931348 |
2024-02-21T15:51:47 Z |
vjudge1 |
Fruits (NOI22_fruits) |
C++17 |
|
1000 ms |
42832 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 5e5+5, M = 5e3+3, inf = LLONG_MAX;
int n, mxA, mxC, a[N], c[N], pre[N], preDp[N], dp[M][M];
bitset<N> vis;
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
mxA = mxC = -inf;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] != -1) {
a[i]--;
vis[a[i]] = 1;
}
mxA = max(mxA, a[i]);
}
for (int i = 0; i < n; i++) {
cin >> c[i];
mxC = max(mxC, c[i]);
}
for (int i = 0; i < n; i++) {
pre[i] = max((i ? pre[i-1] : -1), a[i]);
}
if (mxA == -1) {
int sum = 0;
for (int i = n-1; i >= 0; i--) {
sum += c[i];
cout << sum << " ";
}
cout << "\n";
}/*
else if (mxC == 1) {
int l = 0;
int ans = 0;
for (int i = 0; i < n; i++) {
if (a[i] == -1) {
while (vis[l]) l++;
if (l < n) {
l++;
ans++;
}
}
else {
if (l <= a[i]) {
ans++;
}
l = max(l, a[i]+1);
}
cout << ans << " ";
}
cout << "\n";
}*/
else {
for (int j = 0; j < n; j++) {
if ((a[0] == -1 && !vis[j]) || a[0] == j) dp[0][j] = c[j];
else dp[0][j] = 0;
preDp[j] = max((j ? preDp[j-1] : 0), dp[0][j]);
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < n; j++) {
// dp[i][j] = max coste con los i primeros donde el mas grande es j
dp[i][j] = 0;
if (pre[i] > j) continue;
if (a[i] == -1) {
if (pre[i] < j) {
if (!vis[j]) dp[i][j] = max(dp[i-1][j], (j ? preDp[j-1] : 0) + c[j]);
}
else {
dp[i][j] = dp[i-1][j];
}
}
else {
if (a[i] == j) dp[i][j] = (j ? preDp[j-1] : 0) + c[j];
else {
dp[i][j] = dp[i-1][j];
}
}//cerr << i << " " << j << " " << dp[i][j] << endl;
}
for (int j = 0; j < n; j++) {
preDp[j] = max((j ? preDp[j-1] : 0), dp[i][j]);
}
}
for (int i = 0; i < n; i++) {
int ans = 0;
for (int j = pre[i]; j < n; j++) {
ans = max(ans, dp[i][j]);
}
cout << ans << " ";
}
cout << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10588 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
10708 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
1 ms |
8536 KB |
Output is correct |
9 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
5 ms |
7004 KB |
Output is correct |
4 |
Correct |
39 ms |
14932 KB |
Output is correct |
5 |
Correct |
77 ms |
20812 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10588 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
10708 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
1 ms |
8536 KB |
Output is correct |
9 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10588 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
10708 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
1 ms |
8536 KB |
Output is correct |
9 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1006 ms |
42832 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10588 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
10708 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
1 ms |
8536 KB |
Output is correct |
9 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |