답안 #876402

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
876402 2023-11-21T16:35:48 Z dilanyan 바이오칩 (IZhO12_biochips) C++17
60 / 100
2000 ms 299176 KB
//-------------dilanyan------------\\ 
 
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;

//------------------KarginDefines--------------------\\ 

#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
#define Kargin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Usaco freopen(".in", "r", stdin); freopen(".out", "w", stdout);


//-------------------KarginConstants------------------\\ 
 
const int mod = 1000000007;
const ll inf = 2e9;

//-------------------KarginCode------------------------\\ 
 
const int N = 200005;

int c[N], dp[N][505], s[N];
vector<int> g[N];
int n, m, p, root;

void dfs(int u) {
    s[u] = g[u].empty();
    for (int v : g[u]) {
        dfs(v);
        s[u] += s[v];
        for (int i = min(m, s[u]);i >= 0;--i) {
            for (int j = 0;j <= min(m - i, s[u] - i);++j) {
                dp[u][i + j] = max(dp[u][i + j], dp[u][i] + dp[v][j]);
            }
        }
    }
    dp[u][1] = max(dp[u][1], c[u]);
}

void KarginSolve() {
    cin >> n >> m;
    for (int i = 1; i <= n;++i) {
        cin >> p >> c[i];
        if (p == 0) root = i;
        else g[p].pb(i);
    }
    dfs(root);
    cout << dp[root][m] << '\n';
}

int main() {
    //Usaco
    Kargin;
    int test = 1;
    //cin >> test;
    while (test--) {
        KarginSolve();
    }
    return 0;
}

Compilation message

biochips.cpp:1:1: warning: multi-line comment [-Wcomment]
    1 | //-------------dilanyan------------\\
      | ^
biochips.cpp:8:1: warning: multi-line comment [-Wcomment]
    8 | //------------------KarginDefines--------------------\\
      | ^
biochips.cpp:22:1: warning: multi-line comment [-Wcomment]
   22 | //-------------------KarginConstants------------------\\
      | ^
biochips.cpp:27:1: warning: multi-line comment [-Wcomment]
   27 | //-------------------KarginCode------------------------\\
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 10 ms 23644 KB Output is correct
5 Correct 12 ms 25692 KB Output is correct
6 Correct 13 ms 25692 KB Output is correct
7 Execution timed out 2087 ms 299176 KB Time limit exceeded
8 Execution timed out 2045 ms 298952 KB Time limit exceeded
9 Execution timed out 2047 ms 74640 KB Time limit exceeded
10 Execution timed out 2049 ms 53328 KB Time limit exceeded