# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
281727 | jun6873 | 바이오칩 (IZhO12_biochips) | C++11 | 66 ms | 8908 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200004;
int N, K, a[maxn], o;
vector<int> g[maxn];
vector<int> dp(int x) {
vector<int> res;
for (int y : g[x]) {
vector<int> now = dp(y);
for (int i=now.size()-1; i>=1; i--) now[i] -= now[i-1];
res.insert(res.end(), now.begin(), now.end());
}
sort(res.begin(), res.end());
reverse(res.begin(), res.end());
if (res.size() >= K) res.resize(K);
for (int i=1; i<res.size(); i++) res[i] += res[i-1];
if (res.empty()) res.push_back(a[x]);
else res[0] = max(res[0], a[x]);
return res;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> N >> K;
for (int i=1; i<=N; i++) {
int p, x;
cin >> p >> x;
if (p == 0) o = i;
else g[p].push_back(i);
a[i] = x;
}
cout << dp(o)[K-1] << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |