# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
117610 | evpipis | Pinball (JOI14_pinball) | C++17 | 1077 ms | 2156 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;
typedef long long ll;
const int len = 1e5+5;
const ll inf = 1e18;
int lef[len], rig[len], pos[len], cost[len];
ll dp[len][3];
int main(){
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%d %d %d %d", &lef[i], &rig[i], &pos[i], &cost[i]);
ll ans = inf;
for (int i = 1; i <= n; i++){
ll d0 = inf, d1 = inf, d2 = inf;
if (lef[i] == 1 && rig[i] == m)
d0 = d1 = d2 = cost[i];
else if (lef[i] == 1)
d0 = cost[i];
else if (rig[i] == m)
d1 = cost[i];
for (int j = 1; j < i; j++){
if (pos[j] < lef[i] || rig[i] < pos[j])
continue;
d0 = min(d0, cost[i]+dp[j][0]);
d1 = min(d1, cost[i]+dp[j][1]);
}
d2 = min(d2, d0+d1-cost[i]);
dp[i][0] = d0;
dp[i][1] = d1;
dp[i][2] = d2;
ans = min(ans, d2);
//printf("i = %d, d0 = %lld, d1 = %lld, d2 = %lld\n", i, d0, d1, d2);
}
if (ans == inf)
printf("-1\n");
else
printf("%lld", ans);
return 0;
}
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... |