# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
103048 | luciocf | Pinball (JOI14_pinball) | C++14 | 8 ms | 640 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;
const int maxn = 1e3+10;
const long long inf = 2e18+10;
typedef long long ll;
int l[maxn], r[maxn], p[maxn], d[maxn];
ll dp[2][maxn];
int main(void)
{
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++)
{
scanf("%d %d %d %d", &l[i], &r[i], &p[i], &d[i]);
dp[0][i] = dp[1][i] = inf;
}
for (int i = 1; i <= n; i++)
{
if (l[i] == 1) dp[0][i] = d[i];
for (int j = i-1; j >= 1; j--)
if (p[j] >= l[i] && p[j] <= r[i])
dp[0][i] = min(dp[0][i], 1ll*d[i]+dp[0][j]);
}
for (int i = 1; i <= n; i++)
{
if (r[i] == m) dp[1][i] = d[i];
for (int j = i-1; j >= 1; j--)
if (p[j] >= l[i] && p[j] <= r[i])
dp[1][i] = min(dp[1][i], 1ll*d[i]+dp[1][j]);
}
ll ans = inf;
for (int i = 1; i <= n; i++)
if (dp[0][i] != inf && dp[1][i] != inf)
ans = min(ans, dp[0][i]+dp[1][i]-1ll*d[i]);
if (ans == inf) printf("-1\n");
else 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... |