제출 #755977

#제출 시각아이디문제언어결과실행 시간메모리
755977MohamedFaresNebiliPinball (JOI14_pinball)C++14
51 / 100
1064 ms2392 KiB
#include <bits/stdc++.h>

        using namespace std;
        using ll = long long;

        #define int ll

        int M, N;
        array<int, 4> A[100005];

        int32_t main() {
            ios_base::sync_with_stdio(0);
            cin.tie(0); cout.tie(0);
            cin >> M >> N;
            for(int l = 0; l < M; l++) {
                cin >> A[l][0] >> A[l][1] >> A[l][2] >> A[l][3];
            }
            vector<int> L(M, 1e18);
            vector<int> R(M, 1e18);
            for(int l = 0; l < M; l++) {
                if(A[l][0] == 1)
                    L[l] = A[l][3];
                else {
                    for(int i = 0; i < l; i++) {
                        if(A[i][2] >= A[l][0] && A[i][2] <= A[l][1]) {
                            L[l] = min(L[l], L[i] + A[l][3]);
                        }
                    }
                }
                if(A[l][1] == N)
                    R[l] = A[l][3];
                else {
                    for(int i = 0; i < l; i++) {
                        if(A[i][2] >= A[l][0] && A[i][2] <= A[l][1]) {
                            R[l] = min(R[l], R[i] + A[l][3]);
                        }
                    }
                }
            }
            int res = 1e18;
            for(int l = 0; l < M; l++)
                res = min(res, L[l] + R[l] - A[l][3]);
            cout << (res == 1e18 ? -1 : res) << "\n";
        }




#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...