답안 #85247

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
85247 2018-11-19T01:37:54 Z zoooma13 바이오칩 (IZhO12_biochips) C++14
0 / 100
97 ms 7484 KB
#include <bits/stdc++.h>
using namespace std;

#define MAX_N 100005
#define MAX_M 1003
#define INF 0x3f3f3f3f

int N ,M;
int A ,B;
int Mem[MAX_N];
vector <int> Adj[MAX_N];

int dp[MAX_M][MAX_N];
void Solve(int v)
{
    int dp_new[M+1] ,dp_all[M+1] = {0};
    for(int i : Adj[v])
    {
        Solve(i);

        memset(dp_new ,-INF ,sizeof dp_new);
        for(int j=1; j<=M; j++)
        for(int k=0; k<=M-j; k++)
            dp_new[j+k] = max(dp_new[j+k] ,dp_all[k] + dp[j][i]);

        for(int k=0; k<=M; k++)
            dp_all[k] = max(dp_all[k] ,dp_new[k]);
    }

    for(int l=0; l<=M; l++)
        dp[l][v] = dp_all[l];
    dp[1][v] = max(dp[1][v] ,Mem[v]);
}

int main()
{
    scanf("%d%d",&N,&M); assert(N < MAX_N && M < MAX_M);

    int root;
    for(int i=1; i<=N; i++)
    {
        scanf("%d%d",&A,&B);

        Mem[i] = B;
        if(A == 0)
            root = i;
        else
            Adj[A].push_back(i);
    }

    Solve(root);
    printf("%d\n",dp[M][root]);
}

Compilation message

biochips.cpp: In function 'int main()':
biochips.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&N,&M); assert(N < MAX_N && M < MAX_M);
     ~~~~~^~~~~~~~~~~~~~
biochips.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&A,&B);
         ~~~~~^~~~~~~~~~~~~~
biochips.cpp:52:11: warning: 'root' may be used uninitialized in this function [-Wmaybe-uninitialized]
     printf("%d\n",dp[M][root]);
     ~~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2872 KB Output is correct
3 Correct 4 ms 2980 KB Output is correct
4 Correct 32 ms 5500 KB Output is correct
5 Correct 65 ms 6324 KB Output is correct
6 Correct 97 ms 7484 KB Output is correct
7 Runtime error 17 ms 7484 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -