Submission #516004

# Submission time Handle Problem Language Result Execution time Memory
516004 2022-01-20T09:40:56 Z Jeff12345121 Pinball (JOI14_pinball) C++14
29 / 100
1000 ms 340 KB
#include <bits/stdc++.h>
#define int long long
#define in cin
#define out cout
using namespace std;

//ifstream in("in.in");
//ofstream out("out.out");

int n, m;
const int inf = (1LL << 60);
struct Dev {
    int l, r, hole, cost;
};
vector<Dev> dev;
template <typename F>
int getDp(int len, Dev goal, F f) {
    /// we want to have all the pinballs take it past left
    // dp[i] = minCost to get all balls to this device
    vector<int> dp(len + 1);
    for (int i = 1; i <= len; i++) {
        dp[i] = inf;
    }
    int ans = inf;
    for (int i = 1; i <= len; i++) {
        if (f(dev[i])) {
            dp[i] = dev[i].cost;
        }
        for (int j = 1; j < i; j++) {
            if (dev[i].l <= dev[j].hole && dev[j].hole <= dev[i].r) {
                dp[i] = min(dp[i], dp[j] + dev[i].cost);
            }
        }
        if (goal.l <= dev[i].hole && dev[i].hole <= goal.r) {
            ans = min(ans, dp[i]);
        }
    }
    return ans;
}
int32_t main() {
    in >> m >> n;
    /// m is number of lines, n is number of collumns

    dev.resize(m + 1);
    for (int i = 1; i <= m; i++) {
        int l, r, hole, cost;
        in >> l >> r >> hole >> cost;
        dev[i] = {l, r, hole, cost};
    }

    int ans = inf;
    for (int i = 1; i <= m; i++) {
        /// i is middle
        int leftCost, rightCost;
        if (dev[i].l > 1) {
            leftCost = getDp(i - 1, dev[i], [&](Dev x) {
                return x.l == 1;
            });
        } else {
            leftCost = 0;
        }

        if (dev[i].r < n) {
            rightCost = getDp(i - 1, dev[i], [&](Dev x) {
                return x.r == n;
            });
        } else {
            rightCost = 0;
        }

        ans = min(ans, leftCost + rightCost + dev[i].cost);
        // cout << "\n";
    }

    if (ans == inf) {
        out << "-1\n";
    } else {
        out << ans << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 272 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 272 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 8 ms 332 KB Output is correct
10 Correct 8 ms 324 KB Output is correct
11 Correct 9 ms 324 KB Output is correct
12 Correct 7 ms 332 KB Output is correct
13 Correct 6 ms 332 KB Output is correct
14 Correct 5 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 272 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 8 ms 332 KB Output is correct
10 Correct 8 ms 324 KB Output is correct
11 Correct 9 ms 324 KB Output is correct
12 Correct 7 ms 332 KB Output is correct
13 Correct 6 ms 332 KB Output is correct
14 Correct 5 ms 332 KB Output is correct
15 Correct 2 ms 292 KB Output is correct
16 Correct 32 ms 332 KB Output is correct
17 Execution timed out 1083 ms 340 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 272 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 8 ms 332 KB Output is correct
10 Correct 8 ms 324 KB Output is correct
11 Correct 9 ms 324 KB Output is correct
12 Correct 7 ms 332 KB Output is correct
13 Correct 6 ms 332 KB Output is correct
14 Correct 5 ms 332 KB Output is correct
15 Correct 2 ms 292 KB Output is correct
16 Correct 32 ms 332 KB Output is correct
17 Execution timed out 1083 ms 340 KB Time limit exceeded
18 Halted 0 ms 0 KB -