답안 #218209

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
218209 2020-04-01T14:17:47 Z SamAnd Fireworks (APIO16_fireworks) C++17
19 / 100
26 ms 1792 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 302;
const long long INF = 1000000009000000009;

int n, m;
int p[N];
vector<pair<int, int> > a[N];

long long dp[N][N];
long long dpp[N][N];
void dfs(int x)
{
    if (x > n)
    {
        dp[x][0] = 0;
        return;
    }
    for (int i = 0; i < a[x].size(); ++i)
    {
        int h = a[x][i].first;
        dfs(h);
        for (int j = 0; j < N; ++j)
        {
            for (int k = 0; j + k < N; ++k)
            {
                dpp[h][j + k] = min(dpp[h][j + k], dp[h][j] + abs(a[x][i].second - k));
            }
        }
    }
    for (int j = 0; j < N; ++j)
    {
        dp[x][j] = 0;
        for (int i = 0; i < a[x].size(); ++i)
        {
            int h = a[x][i].first;
            dp[x][j] += dpp[h][j];
            dp[x][j] = min(dp[x][j], INF);
        }
    }
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 2; i <= n; ++i)
    {
        int d;
        scanf("%d%d", &p[i], &d);
        a[p[i]].push_back(m_p(i, d));
    }
    for (int i = n + 1; i <= n + m; ++i)
    {
        int d;
        scanf("%d%d", &p[i], &d);
        a[p[i]].push_back(m_p(i, d));
    }
    for (int i = 1; i <= n + m; ++i)
    {
        for (int j = 0; j < N; ++j)
            dpp[i][j] = dp[i][j] = INF;
    }
    dfs(1);
    long long ans = INF;
    for (int j = 0; j < N; ++j)
        ans = min(ans, dp[1][j]);
    printf("%lld\n", ans);
    return 0;
}

Compilation message

fireworks.cpp: In function 'void dfs(int)':
fireworks.cpp:20:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a[x].size(); ++i)
                     ~~^~~~~~~~~~~~~
fireworks.cpp:35:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < a[x].size(); ++i)
                         ~~^~~~~~~~~~~~~
fireworks.cpp: In function 'int main()':
fireworks.cpp:46: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:50:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &p[i], &d);
         ~~~~~^~~~~~~~~~~~~~~~~~~
fireworks.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &p[i], &d);
         ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 12 ms 512 KB Output is correct
3 Correct 9 ms 640 KB Output is correct
4 Correct 11 ms 768 KB Output is correct
5 Correct 12 ms 896 KB Output is correct
6 Correct 14 ms 896 KB Output is correct
7 Correct 15 ms 1024 KB Output is correct
8 Correct 17 ms 1152 KB Output is correct
9 Correct 18 ms 1280 KB Output is correct
10 Correct 19 ms 1408 KB Output is correct
11 Correct 20 ms 1536 KB Output is correct
12 Correct 22 ms 1536 KB Output is correct
13 Correct 26 ms 1792 KB Output is correct
14 Correct 24 ms 1792 KB Output is correct
15 Correct 26 ms 1776 KB Output is correct
16 Correct 25 ms 1792 KB Output is correct
17 Correct 25 ms 1792 KB Output is correct
18 Correct 24 ms 1664 KB Output is correct
19 Correct 25 ms 1792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -