답안 #685000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
685000 2023-01-23T04:31:32 Z saayan007 바이오칩 (IZhO12_biochips) C++14
0 / 100
122 ms 9012 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];

    a[0][0] = 0;
    fur(y, 1, m) {
        a[0][y] = -inf;
    }

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

    dp[cur][1] = max(s[cur], dp[cur][1]);
    fur(j, 2, m) {
        dp[cur][j] = a[k][j];
    }
}

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;
        }
    }

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

    dfs(root, -1);
    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 Incorrect 0 ms 480 KB Output isn't correct
2 Incorrect 0 ms 468 KB Output isn't correct
3 Incorrect 1 ms 596 KB Output isn't correct
4 Incorrect 48 ms 8060 KB Output isn't correct
5 Incorrect 72 ms 9012 KB Output isn't correct
6 Incorrect 122 ms 9000 KB Output isn't correct
7 Runtime error 1 ms 980 KB Execution killed with signal 11
8 Runtime error 1 ms 980 KB Execution killed with signal 11
9 Runtime error 3 ms 2132 KB Execution killed with signal 11
10 Runtime error 3 ms 2136 KB Execution killed with signal 11