Submission #1304730

#TimeUsernameProblemLanguageResultExecution timeMemory
1304730quollcucumber`Pinball (JOI14_pinball)C++20
11 / 100
6 ms8260 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define mod 1000007
int ar[mod];
int find(int a, int b) {
    return ((a * 1000000) % mod + b) % mod;
}
signed main(){
    int m, n;
    cin>> m >> n;
    pair<pair<int, int>, pair<int, int>> arr[m];
    for(int i = 0; i < m;i ++) {
        cin >> arr[i].first.first >> arr[i].first.second >> arr[i].second.first >> arr[i].second.second;
    }
    // int best[m][m]; // fist is arr[i].first.first, second is arr[i].second.second
    vector<pair<int, int>> best;
    // for(int i = 0; i < m; i++) {
    //     for(int j = 0; j < m; j++) {
    //         best[i][j] = LONG_LONG_MAX;
    //     }
    // }
    for(int i = m-1; i >= 0; i--) {
        if(ar[find(arr[i].first.first, arr[i].first.second)] == 0ll) {
            ar[find(arr[i].first.first,arr[i].first.second)] = arr[i].second.second;
            best.push_back({arr[i].first.first, arr[i].first.second});
        }else {
            ar[find(arr[i].first.first, arr[i].first.second)] = min(ar[find(arr[i].first.first, arr[i].first.second)], arr[i].second.second);
        }
        for(pair<int, int> j : best) {
            if(arr[i].second.first >= j.first && arr[i].second.first <= j.second) {
                int left = min(j.first, arr[i].first.first);
                int right = max(j.second, arr[i].first.second);
                if(ar[find(left, right)] == 0) {
                    ar[find(left, right)] = ar[find(j.first,j.second)] + arr[i].second.second;
                    best.push_back({left, right});
                }else {
                    ar[find(left,right)] = min(ar[find(left,right)] , ar[find(j.first,j.second)] + arr[i].second.second);
                }
            }
        }
    }
    if(ar[find(1, n)] == 0) {
        cout<<-1<<'\n';
    }else {
        cout<<ar[find(1,n)] <<'\n';
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...