# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
337138 | nvmdava | 바이오칩 (IZhO12_biochips) | C++17 | 363 ms | 403308 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 200'005;
const ll MOD = 1'000'000'007;
const int INF = 0x3f3f3f3f;
int dp[N][505];
vector<int> ch[N];
int cnt = 1, w[N], ww[N], l[N];
void dfs(int v){
int t = cnt;
for(auto& x : ch[v])
dfs(x);
ww[cnt] = w[v];
l[cnt++] = t;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin>>n>>m;
int root;
for(int p, i = 1; i <= n; ++i){
cin>>p>>w[i];
if(p)
ch[p].push_back(i);
else
root = i;
}
dfs(root);
for(int i = 0; i <= n; ++i)
for(int j = 1; j <= m; ++j)
dp[i][j] = -0x3f3f3f3f;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
dp[i][j] = max(dp[i - 1][j], dp[l[i] - 1][j - 1] + ww[i]);
cout<<dp[n][m];
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |