답안 #769948

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
769948 2023-06-30T14:33:23 Z shrimb Fruits (NOI22_fruits) C++17
6 / 100
37 ms 596 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 = 202;

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

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

    for (int i = 1 ; 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 = 1 ; i <= n ; i++) {
        memset(dp, -1, sizeof dp);
        cout << rec(1, 0, i + 1) << " ";
    }
}

Compilation message

Main.cpp:14:1: warning: multi-line comment [-Wcomment]
   14 | //\
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 0 ms 596 KB Output is correct
6 Correct 0 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 0 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 0 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 596 KB Output is correct
2 Incorrect 1 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 0 ms 596 KB Output is correct
6 Correct 0 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 0 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 0 ms 596 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Incorrect 4 ms 596 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 0 ms 596 KB Output is correct
6 Correct 0 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 0 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 0 ms 596 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Incorrect 4 ms 596 KB Output isn't correct
13 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 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 0 ms 596 KB Output is correct
6 Correct 0 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 0 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 0 ms 596 KB Output is correct
11 Correct 37 ms 596 KB Output is correct
12 Incorrect 1 ms 256 KB Output isn't correct
13 Halted 0 ms 0 KB -