Submission #1304711

#TimeUsernameProblemLanguageResultExecution timeMemory
1304711quollcucumber`Pinball (JOI14_pinball)C++20
11 / 100
1114 ms459992 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    int m, n;
    cin>> m >> n;
    int fall[n+1];
    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;
    }
    queue<vector<bool>> q;
    q.push({});
    for(int i = 0; i< m; i++) {
        int sz = q.size();
        for(int j = 0; j  < sz; j++) {
            vector<bool> a = q.front();
            q.pop();
            a.push_back(true);
            q.push(a);
            a.pop_back();
            a.push_back(false);
            q.push(a);
        }
    }
    int minval = LONG_LONG_MAX;
    while(!q.empty()) {
        for(int i = 1; i <= n; i++) fall[i] = i;
        vector<bool> vec = q.front();
        q.pop();
        int total = 0;
        for(int i = 0; i < m; i++) {
            if(vec[i]) {
                total += arr[i].second.second;
                for(int j = 1; j <= n; j++) {
                    if(fall[j] >= arr[i].first.first && fall[j] <= arr[i].first.second) {
                        fall[j] = arr[i].second.first;
                    }
                }
            }
        }
        set<int> s;
        for(int i = 1; i <= n; i++) {
            s.insert(fall[i]);
        }
        if(s.size() == 1) {
            minval = min(minval, total);
        }
    }
    if(minval == LONG_LONG_MAX) {
        cout<<-1<<'\n';
    }else {
        cout<<minval<<'\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...