답안 #558667

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
558667 2022-05-08T02:37:03 Z hoanghq2004 Fireworks (APIO16_fireworks) C++14
0 / 100
7 ms 340 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 3e2 + 10;

int n, m;
vector <pair <int, int> > g[N];
int f[N][N];
int cur[N];

void dfs(int u, int p) {
    if (g[u].empty()) {
        memset(f[u], 60, sizeof(f[u]));
        f[u][0] = 0;
    }
    for (auto [v, w]: g[u]) {
        if (v == p) continue;
        dfs(v, u);
        memset(cur, 60, sizeof(cur));
        for (int i = 0; i <= 300; ++i) {
            for (int j = 0; j <= 300; ++j)
                cur[i] = min(cur[i], f[v][j] + abs(i - (w + j)));
        }
        for (int i = 0; i <= 300; ++i) f[u][i] += cur[i];
    }
}

int main() {
    ios :: sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    n += m;
    for (int v = 2; v <= n; ++v) {
        int u, w;
        cin >> u >> w;
        g[u].push_back({v, w});
    }
    dfs(1, 0);
    cout << *min_element(f[1], f[1] + 300 + 1);
}

Compilation message

fireworks.cpp: In function 'void dfs(int, int)':
fireworks.cpp:25:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   25 |     for (auto [v, w]: g[u]) {
      |               ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 4 ms 340 KB Output is correct
3 Incorrect 7 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -