# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
749530 | 2023-05-28T07:16:01 Z | 반딧불(#9967) | Fruits (NOI22_fruits) | C++17 | 28 ms | 31712 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n; int arr[2002]; bool taken[2002]; ll cost[2002]; ll DP[2002][2002]; int main(){ scanf("%d", &n); for(int i=1; i<=n; i++){ scanf("%d", &arr[i]); if(arr[i] != -1) taken[arr[i]] = 1; } for(int i=1; i<=n; i++) scanf("%lld", &cost[i]); for(int i=0; i<=n; i++) for(int j=0; j<=n; j++) DP[i][j] = -1e18; DP[0][0] = 0; for(int i=1; i<=n; i++){ if(arr[i] != -1){ for(int j=0; j<=n; j++){ DP[i][max(j, arr[i])] = max(DP[i][max(j, arr[i])], DP[i-1][j] + (arr[i] > j ? cost[arr[i]] : 0)); } } else{ for(int j=0; j<=n; j++) if(i<=j) DP[i][j] = max(DP[i][j], DP[i-1][j]); ll tmp = -1e18; for(int j=0; j<=n; j++){ if(!taken[j]) DP[i][j] = max(DP[i][j], tmp + cost[j]); tmp = max(tmp, DP[i-1][j]); } } ll MX = 0; for(int j=0; j<=n; j++) MX = max(MX, DP[i][j]); printf("%lld ", MX); } // puts("\n"); // for(int i=0; i<=n; i++){ // printf("%d: ", i); // for(int j=0; j<=n; j++) printf("%lld ", DP[i][j]); // puts(""); // } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 340 KB | Output is correct |
10 | Incorrect | 1 ms | 340 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1364 KB | Output is correct |
2 | Correct | 28 ms | 31712 KB | Output is correct |
3 | Incorrect | 1 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 340 KB | Output is correct |
10 | Incorrect | 1 ms | 340 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 340 KB | Output is correct |
10 | Incorrect | 1 ms | 340 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 340 KB | Output is correct |
10 | Incorrect | 1 ms | 340 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |