제출 #435933

#제출 시각아이디문제언어결과실행 시간메모리
435933cgiosy바이오칩 (IZhO12_biochips)C++17
0 / 100
2 ms1868 KiB
#include <bits/stdc++.h> using namespace std; void mx(int&a, int b) { a=max(a, b); } int main() { ios::sync_with_stdio(0);cin.tie(0); int N, K, r; cin>>N>>K; int D[2][200004], F[N+1], G[N+1]{}, W[N+1]; for(int i=1; i<=N; i++) { int p; cin>>p>>W[i]; if(p) F[i]=G[p], G[p]=i; else r=i; } int n[2]{}, d=0; function<int(int)> dfs=[&](int i) { int p=n[d]; for(int e=G[i]; e; e=F[e]) { d^=1; int m=dfs(e); d^=1; int q=n[d^1]-=m, j=min(n[d]-p+m, K); while(n[d]<p+j) D[d][n[d]++]=-1e9; while(--j) for(int k=min(m, j); k--;) mx(D[d][p+j], D[d][p+j-k-1]+D[d^1][q+k]); for(int k=0; k<m; k++) mx(D[d][p+k], D[d^1][q+k]); } if(p==n[d]) D[d][n[d]++]=W[i]; else mx(D[d][p], W[i]); return n[d]-p; }; cout<<D[0][dfs(r)-1]<<'\n'; }

컴파일 시 표준 에러 (stderr) 메시지

biochips.cpp: In function 'int main()':
biochips.cpp:7:12: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
    7 |  int N, K, r;
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...