Submission #200781

# Submission time Handle Problem Language Result Execution time Memory
200781 2020-02-08T06:44:36 Z BThero Fireworks (APIO16_fireworks) C++17
0 / 100
12 ms 508 KB
// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()
                                                  
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;   
typedef pair<int, int> pii;
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int MAXN = (int)3e2 + 5;
const int INF = (int)1e6;

int par[MAXN], arr[MAXN];

int dp[MAXN][MAXN];

vector<int> adj[MAXN];

int sum[MAXN];
        
int n, m;

void pdfs(int v, int pr = -1) {
    for (int to : adj[v]) {
        if (to != pr) {
            sum[to] = sum[v] + arr[to];
            pdfs(to, v);
        }
    }    
}

void dfs(int v, int pr = -1) {
    if (v > n) {
        fill(dp[v], dp[v] + MAXN, INF);
        dp[v][sum[v]] = 0;
        return;
    }

    for (int to : adj[v]) {
        if (to == pr) {
            continue;
        }

        dfs(to, v);

        for (int i = 0; i <= 300; ++i) {
            int best = INF;

            for (int j = 0; j <= 300; ++j) {
                int x = i - j;

                //if (arr[to] + x >= 0) {
                    best = min(best, dp[to][j] + abs(x));
                //}
            }            

            dp[v][i] += best;                        
        }
    }    
}

void solve() {
    scanf("%d %d", &n, &m);

    for (int i = 2; i <= n + m; ++i) {
        scanf("%d %d", &par[i], &arr[i]);
        adj[par[i]].pb(i);
    }

    pdfs(1);
    dfs(1);
    int ans = INF;

    for (int i = 0; i <= 300; ++i) {
        ans = min(ans, dp[1][i]);
    }

    printf("%d\n", ans);
}

int main() {
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Compilation message

fireworks.cpp: In function 'void solve()':
fireworks.cpp:76: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:79:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &par[i], &arr[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 508 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 6 ms 376 KB Output is correct
2 Correct 9 ms 376 KB Output is correct
3 Incorrect 12 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 508 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 6 ms 508 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -