답안 #769924

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
769924 2023-06-30T13:49:20 Z shrimb Fruits (NOI22_fruits) C++17
0 / 100
21 ms 656 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 = 201;

int n;
int a[maxn], c[maxn], b[maxn], taken[maxn], pref[maxn], preft[maxn];

int dp[maxn][maxn];

int rec (int i, int j, int k) {
    if (i == k) return 0;
    if (~dp[i][j]) return dp[i][j];
    int pj = j;
    if (~a[i]) {
        bool b = a[i] >= j;
        while (j <= n && (a[i] >= j)) j++;
        return dp[i][pj] = rec(i + 1, j, k) + (b ? c[a[i]] : 0);
    }
    while (j <= n && taken[j]) j++;
    if (pref[i] < preft[j]) dp[i][pj] = rec(i + 1, j, k);
    if (j != n + 1) dp[i][pj] = max({dp[i][pj], rec(i + 1, j + 1, k) + c[j], rec(i, j + 1, k)});
    return dp[i][pj];
}

signed main () {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;

    for (int i = 0 ; i < n ; i++) {
        cin >> a[i];
        if (a[i] != -1) taken[a[i]] = 1;
        else pref[i] = 1;
        if (i) pref[i] += pref[i-1];
    }

    for (int i = 1 ; i <= n ; i++) {
        if (taken[i] == 0) preft[i] = 1;
        preft[i] += preft[i-1];
        cin >> c[i];
    }
    preft[n + 1] = preft[n];

    for (int i = 0 ; i < n ; i++) {
        memset(dp, -1, sizeof dp);
        cout << rec(0, 1, i + 1) << " ";
    }
}

Compilation message

Main.cpp:14:1: warning: multi-line comment [-Wcomment]
   14 | //\
      | ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 656 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -