#include"bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define endl '\n'
#define mod 1000000007
//\
#define mod 1686876991
const int maxn = 2002;
int n;
int dp[maxn][maxn];
int a[maxn], c[maxn], p[maxn], e[maxn], mx[maxn];
bool used[maxn];
signed main () {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 1 ; i <= n ; i++) {
cin >> a[i];
if (~a[i]) used[a[i]] = 1;
else e[i] = 1;
e[i] += e[i-1];
mx[i] = max(mx[i-1], a[i]);
}
for (int i = 1 ; i <= n ; i++) {
cin >> c[i];
p[i] = p[i - 1] + !used[i];
}
for (int i = 1 ; i <= n ; i++) {
for (int j = 1 ; j <= n ; j++) {
dp[i][j] = dp[i][j-1];
if (mx[i - 1] > j) {
dp[i][j] = -1e15;
} else {
if (a[i] == -1) {
if (!used[j]) dp[i][j] = max(dp[i][j], dp[i-1][j-1] + c[j]);
if (e[i] <= p[j]) dp[i][j] = max(dp[i][j], dp[i-1][j]);
else dp[i][j] = -1e15;
} else {
if (j < a[i]) dp[i][j] = -1e15;
else dp[i][j] = max(dp[i][j], dp[i-1][j]);
if (j == a[i]) dp[i][j] = max(dp[i][j], dp[i-1][j-1] + c[j]);
}
}
}
cout << max(0ll,dp[i][n]) << " ";
}
}
Compilation message
Main.cpp:14:1: warning: multi-line comment [-Wcomment]
14 | //\
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1364 KB |
Output is correct |
2 |
Correct |
24 ms |
31700 KB |
Output is correct |
3 |
Runtime error |
148 ms |
64200 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
1364 KB |
Output is correct |
12 |
Correct |
1 ms |
1364 KB |
Output is correct |
13 |
Correct |
1 ms |
1364 KB |
Output is correct |
14 |
Correct |
1 ms |
724 KB |
Output is correct |
15 |
Correct |
1 ms |
724 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Correct |
0 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
1236 KB |
Output is correct |
22 |
Correct |
1 ms |
1108 KB |
Output is correct |
23 |
Correct |
1 ms |
1236 KB |
Output is correct |
24 |
Correct |
1 ms |
980 KB |
Output is correct |
25 |
Correct |
1 ms |
980 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
1364 KB |
Output is correct |
12 |
Correct |
1 ms |
1364 KB |
Output is correct |
13 |
Correct |
1 ms |
1364 KB |
Output is correct |
14 |
Correct |
1 ms |
724 KB |
Output is correct |
15 |
Correct |
1 ms |
724 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Correct |
0 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
1236 KB |
Output is correct |
22 |
Correct |
1 ms |
1108 KB |
Output is correct |
23 |
Correct |
1 ms |
1236 KB |
Output is correct |
24 |
Correct |
1 ms |
980 KB |
Output is correct |
25 |
Correct |
1 ms |
980 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
16 ms |
31684 KB |
Output is correct |
29 |
Correct |
22 ms |
31688 KB |
Output is correct |
30 |
Correct |
17 ms |
31716 KB |
Output is correct |
31 |
Correct |
7 ms |
12244 KB |
Output is correct |
32 |
Correct |
8 ms |
12244 KB |
Output is correct |
33 |
Correct |
15 ms |
23944 KB |
Output is correct |
34 |
Correct |
17 ms |
27004 KB |
Output is correct |
35 |
Correct |
12 ms |
23888 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
14 ms |
27860 KB |
Output is correct |
39 |
Correct |
16 ms |
25428 KB |
Output is correct |
40 |
Correct |
20 ms |
28628 KB |
Output is correct |
41 |
Correct |
19 ms |
29320 KB |
Output is correct |
42 |
Correct |
19 ms |
29784 KB |
Output is correct |
43 |
Correct |
20 ms |
29884 KB |
Output is correct |
44 |
Correct |
21 ms |
30108 KB |
Output is correct |
45 |
Correct |
21 ms |
31712 KB |
Output is correct |
46 |
Correct |
24 ms |
31716 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
560 ms |
64132 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
1364 KB |
Output is correct |
12 |
Correct |
24 ms |
31700 KB |
Output is correct |
13 |
Runtime error |
148 ms |
64200 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |