Submission #117610

#TimeUsernameProblemLanguageResultExecution timeMemory
117610evpipisPinball (JOI14_pinball)C++17
51 / 100
1077 ms2156 KiB
#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)

pinball.cpp: In function 'int main()':
pinball.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
pinball.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d %d", &lef[i], &rig[i], &pos[i], &cost[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...