# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
261955 | Saboon | Fireworks (APIO16_fireworks) | C++14 | 7 ms | 512 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 300 + 10;
const ll inf = 1e18;
vector<pair<int,int>> t[maxn];
ll dp[maxn][maxn];
int lo[maxn], r[maxn];
void dfs(int v){
if (t[v].empty()){
dp[v][0] = 0;
for (int j = 1; j < maxn; j++)
dp[v][j] = inf;
return;
}
for (auto [u,c] : t[v]){
dfs(u);
for (int i = 0; i < maxn; i++){
ll now = inf;
for (int j = 0; j < maxn; j++)
now = min(now, dp[u][j] + abs(i-j-c));
dp[v][i] += now;
}
}
}
int main(){
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 2; i <= n+m; i++){
int v, c;
cin >> v >> c;
t[v].push_back({i,c});
}
dfs(1);
ll answer = inf;
for (int i = 0; i < maxn; i++)
answer = min(answer, dp[1][i]);
cout << answer << endl;
}
컴파일 시 표준 에러 (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... |