답안 #166382

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
166382 2019-12-02T03:09:12 Z abcdef6199 Fireworks (APIO16_fireworks) C++
19 / 100
38 ms 888 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int, int> II;

const int MAXN = 300 + 10;
int n, m;
vector<II> adj[MAXN];

int dp[MAXN][MAXN];

void dfs(int u) {
    if (adj[u].size() == 0) {
        for (int i = 1; i <= 300; ++i) {
            dp[u][i] = (int)1e9;
        }
        dp[u][0] = 0;
        return;
    }

    dp[u][0] = (int)1e9;
    for (int i = 0; i < (int)adj[u].size(); ++i) {
        int v = adj[u][i].first;
        int w = adj[u][i].second;
        dfs(v);

        for (int x = 1; x <= 300; ++x) {
            int t = (int)1e9;
            for (int y = 0; y <= x; ++y) {
                int d = x - y;
                t = min(t, dp[v][y] + abs(d - w));
            }
            dp[u][x] += t;
        }
    }
}

int main() {
    scanf("%d%d", &n, &m);
    n += m;
    for (int i = 2; i <= n; ++i) {
        int p, w;
        scanf("%d%d", &p, &w);
        adj[p].push_back(II(i, w));
    }

    dfs(1);
    printf("%d\n", *min_element(dp[1] + 1, dp[1] + 1 + 300));
    return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
fireworks.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &p, &w);
         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 8 ms 376 KB Output is correct
5 Correct 10 ms 504 KB Output is correct
6 Correct 10 ms 504 KB Output is correct
7 Correct 12 ms 504 KB Output is correct
8 Correct 14 ms 504 KB Output is correct
9 Correct 14 ms 504 KB Output is correct
10 Correct 16 ms 632 KB Output is correct
11 Correct 17 ms 632 KB Output is correct
12 Correct 19 ms 632 KB Output is correct
13 Correct 20 ms 636 KB Output is correct
14 Correct 22 ms 888 KB Output is correct
15 Correct 21 ms 632 KB Output is correct
16 Correct 22 ms 760 KB Output is correct
17 Correct 38 ms 888 KB Output is correct
18 Correct 21 ms 760 KB Output is correct
19 Correct 27 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -