답안 #770782

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
770782 2023-07-01T23:31:27 Z shrimb Fruits (NOI22_fruits) C++17
0 / 100
779 ms 64240 KB
#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], cnt, 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++) {
        cnt += (a[i] == -1);
        for (int j = 1 ; j <= n ; j++) {
            dp[i][j] = dp[i][j-1];
            if (a[i] == -1) {
                if (mx[i] > j) {
                    dp[i][j] = -1e15;
                } else {
                    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 {
                if (mx[i] > j) {
                    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 << dp[i][n] << " ";
    }


}

Compilation message

Main.cpp:14:1: warning: multi-line comment [-Wcomment]
   14 | //\
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 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 1 ms 340 KB Output is correct
9 Incorrect 0 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 25 ms 31740 KB Output is correct
3 Runtime error 141 ms 64240 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 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 1 ms 340 KB Output is correct
9 Incorrect 0 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 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 1 ms 340 KB Output is correct
9 Incorrect 0 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 779 ms 64208 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 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 1 ms 340 KB Output is correct
9 Incorrect 0 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -