답안 #684999

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684999 2023-01-23T04:28:00 Z saayan007 바이오칩 (IZhO12_biochips) C++14
20 / 100
121 ms 9032 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pi>;
using vpl = vector<pl>;

#define fur(i, a, b) for(ll i = a; i <= (ll)b; ++i)
#define ruf(i, a, b) for(ll i = a; i >= (ll)b; --i)
#define fr first 
#define sc second
#define mp make_pair
#define pb push_back
#define nl "\n"
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

const ll mxn = 1e4L;
const ll mxm = 1e2L;
#warning mxn, mxm are set wrong

const ll inf = 1e12L;
ll n, m;
ll root;
ll p[mxn + 1];
vl adj[mxn + 1];
ll s[mxn + 1];
ll dp[mxn + 1][mxm + 1];

void dfs(ll cur, ll par) {
    ll one = -inf;
    for(auto u : adj[cur]) {
        if(u == par)
            continue;
        dfs(u, cur);
        one = max(one, dp[u][1]);
    }

    ll k = adj[cur].size();
    ll a[k + 1][m + 1];
    fur(i, 0, k) {
        fur(j, 0, m) {
            a[i][j] = -inf;
        }
    } 

    a[0][0] = 0;
    fur(x, 1, k) {
        a[x][0] = 0;
        fur(y, 1, m) {
            fur(z, 0, y) {
                a[x][y] = max(a[x][y], dp[adj[cur][x - 1]][z] + a[x - 1][y - z]);
            }
        }
    }
    fur(j, 2, m) {
        dp[cur][j] = a[k][j];
    }
    dp[cur][0] = 0;
    dp[cur][1] = max(s[cur], one);
}

int main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    fur(i, 1, n) {
        cin >> p[i] >> s[i];

        if(p[i] != 0) {
            adj[i].pb(p[i]);
            adj[p[i]].pb(i);
        } else {
            root = i;
        }
    }

    // cout << "Adj List\n";
    // fur(i, 1, n) {
        // cout << i << " : ";
        // for(auto u : adj[i])
            // cout << u << ' ';
        // cout << nl;
    // }
    // cout <<nl;

    fur(i, 0, n) {
        fur(j, 0, m) {
            // dp[i][j] = a[i][j] = -inf;
            dp[i][j] = -inf;
        }
    }

    // cout << "L, R\n";
    dfs(root, -1);
    // fur(i, 1, n) {
        // cout << l[i] << ' ' << r[i] << nl;
    // }
    // cout << nl;
    // fur(i, 1, n) {
        // fur(j, 0, m) {
            // if(dp[i][j] < 0) {
                // cout << "  -";
            // } else
                // cout << dp[i][j] << ' ';
        // }
        // cout << nl;
    // }
    cout << dp[root][m] << nl;
}

Compilation message

biochips.cpp:24:2: warning: #warning mxn, mxm are set wrong [-Wcpp]
   24 | #warning mxn, mxm are set wrong
      |  ^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 480 KB Output is correct
2 Incorrect 1 ms 480 KB Output isn't correct
3 Correct 1 ms 608 KB Output is correct
4 Incorrect 46 ms 8076 KB Output isn't correct
5 Incorrect 74 ms 9032 KB Output isn't correct
6 Incorrect 121 ms 9016 KB Output isn't correct
7 Runtime error 1 ms 992 KB Execution killed with signal 11
8 Runtime error 1 ms 864 KB Execution killed with signal 11
9 Runtime error 4 ms 2144 KB Execution killed with signal 11
10 Runtime error 4 ms 2212 KB Execution killed with signal 11