# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
131525 | Just_Solve_The_Problem | Pinball (JOI14_pinball) | C++11 | 2 ms | 504 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = (int)1e5 + 7;
const int smalln = (int)1e3 + 7;
int n, m;
int a[maxn], b[maxn], c[maxn], d[maxn];
ll dp[smalln][smalln];
int pos[maxn];
ll go(int i1, int i2) {
if (b[i2] == n) return 0;
ll &res = dp[i1][i2];
if (res != (ll)1e18) return res;
res = 1e18 - 1;
for (int i = 0; i < m; i++) {
if (i1 == i) continue;
if (i < i1) {
if (c[i] <= b[i2] && i < i2) {
if (b[i] > b[i2]) {
res = min(res, go(i1, i) + d[i]);
}
}
} else {
if (a[i] <= c[i1] && c[i1] <= b[i]) {
if (b[i2] > b[i]) {
res = min(res, go(i, i2) + d[i]);
} else {
res = min(res, go(i, i) + d[i]);
}
}
}
}
return res;
}
main() {
scanf("%d %d", &m, &n);
iota(pos, pos + m, 0);
for (int i = 0; i < m; i++) {
scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
}
if (n >= smalln) return 0;
if (n == 1) {
puts("0");
return 0;
}
// work
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
dp[i][j] = 1e18;
}
}
// find ans
ll ans = 1e18;
for (int i = 0; i < m; i++)
if (a[i] == 1)
ans = min(ans, go(i, i) + d[i]);
if (ans == (ll)1e18) ans = -1;
printf("%lld\n", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |