답안 #218211

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
218211 2020-04-01T14:20:18 Z SamAnd Fireworks (APIO16_fireworks) C++17
컴파일 오류
0 ms 0 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));
    }
    if (n == 1)
    {
        long long ans = 0;
        for (int i = 0; i < a[1].size(); ++i)
        {
            long long yans = 0;
            for (int j = 0; j < a[1].size(); ++j)
                yans += abs(a[1][i].second - a[1][j].second);
            ans = min(ans, yans);
        }
        printf("%lld\n", ans):
        return 0;
    }
    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:62:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < a[1].size(); ++i)
                         ~~^~~~~~~~~~~~~
fireworks.cpp:65:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j = 0; j < a[1].size(); ++j)
                             ~~^~~~~~~~~~~~~
fireworks.cpp:69:30: error: expected ';' before ':' token
         printf("%lld\n", ans):
                              ^
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);
         ~~~~~^~~~~~~~~~~~~~~~~~~