Submission #508758

# Submission time Handle Problem Language Result Execution time Memory
508758 2022-01-13T17:22:00 Z Jeff12345121 Pinball (JOI14_pinball) C++14
29 / 100
25 ms 6604 KB
#include <bits/stdc++.h>
#define in cin
#define out cout
#define ll long long
using namespace std;

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

struct device {
    int l, r, hole, cost;
};
vector<device> devices, sortDevices;
const int nmax = 605;
const ll inf = (1LL << 60);
int n, m;
ll dp[nmax][nmax];
void minSelf(ll &a, ll b) {
    if (b < a) {
        a = b;
    }
}
set<int> positions;
unordered_map<int, int> realToNorm, normToReal;
int32_t main() {
    in >> n >> m;
    if (m == 1) {
        out << "0\n";
        return 0;
    }
    devices.resize(n + 1);
    sortDevices.resize(n + 1);
    for (int i = 1; i <= n; i++) {
        int l, r, hole, cost;
        in >> l >> r >> hole >> cost;
        devices[i] = {l, r, hole, cost};
        sortDevices[i] = {l, r, hole, cost};
        positions.insert(l);
        positions.insert(r);
        positions.insert(hole);
    }

    sort(sortDevices.begin() + 1, sortDevices.end(), [&](device x, device y) {
        return x.l < y.l;
    });
    int r = 1;
    for (int i = 1; i <= n; i++) {
        if (sortDevices[i].l > r) {
            out << "-1\n";
            return 0;
        }
        r = max(r, sortDevices[i].r);
    }
    if (r < m) {
        out << "-1\n";
        return 0;
    }

    int nr = 0;
    for (auto k : positions) {
        nr++;
        realToNorm[k] = nr;
        normToReal[nr] = k;
    }

    for (int i = 1; i <= n; i++) {
        devices[i].l = realToNorm[devices[i].l];
        devices[i].r = realToNorm[devices[i].r];
        devices[i].hole = realToNorm[devices[i].hole];
    }
    m = nr;

    /// dp[i][l][r] = using only devices i...n, we have extended the road for the interval
    /// l - r. sum will be in dp[1][1..m]
    for (int i = 0; i <= 1; i++) {
        for (int l = 0; l <= m; l++) {
            for (int r = 0; r <= m; r++) {
                dp[l][r] = inf;
            }
        }
    }
    for (int i = m; i >= 1; i--) {
        dp[i][i] = 0;
    }
    for (int i = n; i >= 1; i--) {
        for (int l = 1; l <= m; l++) {
            for (int r = l; r <= m; r++) {
                minSelf(dp[l][r], dp[l][r]);
                if (dp[l][r] == inf) continue;

                if (l <= devices[i].hole && devices[i].hole <= r) {
                    int newL = min(l, devices[i].l);
                    int newR = max(r, devices[i].r);
                    minSelf(dp[newL][newR], dp[l][r] + devices[i].cost);
                    minSelf(dp[l][r], dp[l][r]);
                }
            }
        }
    }
    if (dp[1][m] == inf) {
        out << "-1\n";
    } else {
        out << dp[1][m] << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 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 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 5 ms 1356 KB Output is correct
11 Correct 7 ms 1612 KB Output is correct
12 Correct 24 ms 3148 KB Output is correct
13 Correct 20 ms 3228 KB Output is correct
14 Correct 25 ms 3148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 5 ms 1356 KB Output is correct
11 Correct 7 ms 1612 KB Output is correct
12 Correct 24 ms 3148 KB Output is correct
13 Correct 20 ms 3228 KB Output is correct
14 Correct 25 ms 3148 KB Output is correct
15 Correct 1 ms 716 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Runtime error 8 ms 6604 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 5 ms 1356 KB Output is correct
11 Correct 7 ms 1612 KB Output is correct
12 Correct 24 ms 3148 KB Output is correct
13 Correct 20 ms 3228 KB Output is correct
14 Correct 25 ms 3148 KB Output is correct
15 Correct 1 ms 716 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Runtime error 8 ms 6604 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -