Submission #40374

# Submission time Handle Problem Language Result Execution time Memory
40374 2018-01-31T12:40:33 Z SpaimaCarpatilor Fireworks (APIO16_fireworks) C++14
19 / 100
415 ms 459676 KB
#include<bits/stdc++.h>

using namespace std;

int N, M, t[309], L[309];
long long maxH, dp[309][309*309], depth[309];
const long long INF = 1LL << 60;
vector < int > v[309];

int modul (int x)
{
    if (x < 0) return -x;
    return x;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &M);
for (int i=2; i<=N + M; i++)
    scanf ("%d %d", &t[i], &L[i]), v[t[i]].push_back (i), depth[i] = depth[t[i]] + L[i], maxH = max (maxH, depth[i]);
for (int nod = N + M; nod > N; nod --)
    for (int i=0; i<=maxH; i++)
        dp[nod][i] = modul (i - L[nod]);
for (int nod = N; nod>=1; nod--)
{
    ///adding
    for (auto son : v[nod])
        for (int i=0; i<=maxH; i++)
            dp[nod][i] += dp[son][i];
    ///shifting
    for (int i=maxH; i>=0; i--)
    {
        dp[nod][i] += L[nod];
        for (int j=1; j<=i; j++)
            if (dp[nod][i - j] + modul (j - L[nod]) < dp[nod][i])
                dp[nod][i] = dp[nod][i - j] + modul (j - L[nod]);
    }
    ///refreshing
/*    long long mini = INF;
    for (int i=0; i<=maxH; i++)
    {
        dp[nod][i] = min (mini + i, dp[nod][i]);
        if (dp[nod][i] - i < mini)
            mini = dp[nod][i] - i;
    }
    mini = INF;
    for (int i=maxH; i>=0; i--)
    {
        dp[nod][i] = min (mini - i, dp[nod][i]);
        if (dp[nod][i] + i < mini)
            mini = dp[nod][i] + i;
    }*/
}
long long ans = INF;
for (int i=0; i<=maxH; i++)
    if (dp[1][i] < ans)
        ans = dp[1][i];
printf ("%lld\n", ans);
return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:21:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 scanf ("%d %d", &N, &M);
                        ^
fireworks.cpp:23:117: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d %d", &t[i], &L[i]), v[t[i]].push_back (i), depth[i] = depth[t[i]] + L[i], maxH = max (maxH, depth[i]);
                                                                                                                     ^
# Verdict Execution time Memory Grader output
1 Runtime error 415 ms 459676 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 459676 KB Output is correct
2 Correct 3 ms 459676 KB Output is correct
3 Correct 4 ms 459676 KB Output is correct
4 Correct 4 ms 459676 KB Output is correct
5 Correct 8 ms 459676 KB Output is correct
6 Correct 7 ms 459676 KB Output is correct
7 Correct 8 ms 459676 KB Output is correct
8 Correct 9 ms 459676 KB Output is correct
9 Correct 10 ms 459676 KB Output is correct
10 Correct 12 ms 459676 KB Output is correct
11 Correct 12 ms 459676 KB Output is correct
12 Correct 13 ms 459676 KB Output is correct
13 Correct 14 ms 459676 KB Output is correct
14 Correct 28 ms 459676 KB Output is correct
15 Correct 15 ms 459676 KB Output is correct
16 Correct 14 ms 459676 KB Output is correct
17 Correct 16 ms 459676 KB Output is correct
18 Correct 15 ms 459676 KB Output is correct
19 Correct 14 ms 459676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 415 ms 459676 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 415 ms 459676 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -