# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
400680 | A_D | Fireworks (APIO16_fireworks) | C++14 | 21 ms | 1016 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define ii pair<int,int>
#define F first
#define S second
#define du long double
using namespace std;
const int N=301;
int a[N];
int dp[N][N];
vector<ii> g[N];
void dfs(int u)
{
for(auto x:g[u]){
dfs(x.F);
for(int j=0;j<=300;j++){
int mn=1e18;
for(int k=0;k<=j;k++){
mn=min(mn,dp[x.F][k]+abs(j-(x.S+k)));
}
dp[u][j]+=mn;
}
}
}
void solve()
{
int n,m;
cin>>n>>m;
for(int i=2;i<=n+m;i++){
int u,c;
scanf("%lld",&u);
scanf("%lld",&c);
g[u].push_back({i,c});
if(i>n){
for(int j=1;j<=300;j++){
dp[i][j]=1e13;
}
}
}
dfs(1);
/*
cout<<endl;
for(int i=1;i<=n+m;i++){
for(int j=1;j<=10;j++){
cout<<dp[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
*/
int mn=1e18;
for(int i=0;i<=300;i++)mn=min(mn,dp[1][i]);
cout<<mn<<endl;
}
main()
{
int t=1;
// cin>>t;
while(t--)solve();
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |