답안 #749532

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
749532 2023-05-28T07:19:18 Z 반딧불(#9967) Fruits (NOI22_fruits) C++17
30 / 100
50 ms 47376 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 sum[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) sum[i][arr[i]] = 1;
    for(int i=n; i>=1; i--) for(int j=1; j<=n; j++) sum[i][j] += sum[i+1][j] + sum[i][j-1] - sum[i+1][j-1];

    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+sum[i][j]<=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

Main.cpp: In function 'int main()':
Main.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
Main.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         scanf("%d", &arr[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
Main.cpp:20:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     for(int i=1; i<=n; i++) scanf("%lld", &cost[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 0 ms 340 KB Output is correct
5 Correct 0 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 2388 KB Output is correct
2 Correct 46 ms 47352 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
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 0 ms 340 KB Output is correct
5 Correct 0 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 2 ms 2388 KB Output is correct
12 Correct 1 ms 2388 KB Output is correct
13 Correct 2 ms 2388 KB Output is correct
14 Correct 1 ms 1236 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 1 ms 1748 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 2004 KB Output is correct
22 Correct 1 ms 1876 KB Output is correct
23 Correct 1 ms 1876 KB Output is correct
24 Correct 1 ms 1748 KB Output is correct
25 Correct 1 ms 1492 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 0 ms 340 KB Output is correct
5 Correct 0 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 2 ms 2388 KB Output is correct
12 Correct 1 ms 2388 KB Output is correct
13 Correct 2 ms 2388 KB Output is correct
14 Correct 1 ms 1236 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 1 ms 1748 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 2004 KB Output is correct
22 Correct 1 ms 1876 KB Output is correct
23 Correct 1 ms 1876 KB Output is correct
24 Correct 1 ms 1748 KB Output is correct
25 Correct 1 ms 1492 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 47 ms 47368 KB Output is correct
29 Correct 47 ms 47308 KB Output is correct
30 Correct 47 ms 47368 KB Output is correct
31 Correct 15 ms 20008 KB Output is correct
32 Correct 16 ms 20028 KB Output is correct
33 Correct 31 ms 35632 KB Output is correct
34 Correct 36 ms 40220 KB Output is correct
35 Correct 31 ms 35612 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 468 KB Output is correct
38 Correct 42 ms 41416 KB Output is correct
39 Correct 33 ms 37972 KB Output is correct
40 Correct 41 ms 42572 KB Output is correct
41 Correct 42 ms 43856 KB Output is correct
42 Correct 41 ms 44364 KB Output is correct
43 Correct 44 ms 44620 KB Output is correct
44 Correct 43 ms 44728 KB Output is correct
45 Correct 50 ms 47360 KB Output is correct
46 Correct 50 ms 47376 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
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 0 ms 340 KB Output is correct
5 Correct 0 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 2388 KB Output is correct
12 Correct 46 ms 47352 KB Output is correct
13 Incorrect 0 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -