Submission #916260

# Submission time Handle Problem Language Result Execution time Memory
916260 2024-01-25T14:50:15 Z hariaakas646 Fireworks (APIO16_fireworks) C++14
19 / 100
13 ms 944 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, l, r) for(int i=l; i<r; i++)
#define frange(i, l) forr(i, 0, l)
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef long long lli;
typedef vector<vi> vvi;
typedef vector<lli> vll;
typedef vector<bool> vb;
typedef set<int> seti;
typedef multiset<int> mseti;

void usaco()
{
    freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
}

int n, m;

vector<vector<pair<int, lli>>> graph;
// vll dp;

vector<lli> dfs(int x) {
    if(x > n) {
        vector<lli> vec(301, 1e16);
        vec[0] = 0;
        return vec;
    }
    lli tot = 0;
    vll vec(301, 0);
    for(auto e : graph[x]) {
        auto v = dfs(e.f);
        forr(i, 0, 301) {
            lli mi = 1e16;
            forr(j, 0, i+1) {
                mi = min(mi, abs(j+e.s-i) + v[j]);
            }
            vec[i] += mi;
        }
    }
    return vec;
}

int main() {
    // usaco();
    
    scd(n);
    scd(m);

    graph = vector<vector<pair<int, lli>>>(n+1);

    forr(i, 2, n+m+1) {
        int pa;
        lli c;
        scd(pa);
        sclld(c);
        graph[pa].pb(mp(i, c));
    }
    vll out = dfs(1);

    lli mi = 1e16;
    forr(i, 0, 301) mi = min(mi, out[i]);

    // printf("%lld", *min_element(all(dfs(1))));
    printf("%lld", mi);
}

Compilation message

fireworks.cpp: In function 'std::vector<long long int> dfs(int)':
fireworks.cpp:41:9: warning: unused variable 'tot' [-Wunused-variable]
   41 |     lli tot = 0;
      |         ^~~
fireworks.cpp: In function 'void usaco()':
fireworks.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fireworks.cpp: In function 'int main()':
fireworks.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
fireworks.cpp:59:5: note: in expansion of macro 'scd'
   59 |     scd(n);
      |     ^~~
fireworks.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
fireworks.cpp:60:5: note: in expansion of macro 'scd'
   60 |     scd(m);
      |     ^~~
fireworks.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
fireworks.cpp:67:9: note: in expansion of macro 'scd'
   67 |         scd(pa);
      |         ^~~
fireworks.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 | #define sclld(t) scanf("%lld", &t)
      |                  ~~~~~^~~~~~~~~~~~
fireworks.cpp:68:9: note: in expansion of macro 'sclld'
   68 |         sclld(c);
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 5 ms 604 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Correct 6 ms 360 KB Output is correct
7 Correct 7 ms 348 KB Output is correct
8 Correct 8 ms 716 KB Output is correct
9 Correct 9 ms 460 KB Output is correct
10 Correct 9 ms 348 KB Output is correct
11 Correct 13 ms 348 KB Output is correct
12 Correct 11 ms 464 KB Output is correct
13 Correct 12 ms 348 KB Output is correct
14 Correct 13 ms 944 KB Output is correct
15 Correct 13 ms 348 KB Output is correct
16 Correct 13 ms 468 KB Output is correct
17 Correct 13 ms 344 KB Output is correct
18 Correct 13 ms 348 KB Output is correct
19 Correct 13 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -