# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1138014 | SmuggingSpun | Pinball (JOI14_pinball) | C++20 | 2 ms | 396 KiB |
#include<bits/stdc++.h>
#define taskname "B"
using namespace std;
typedef long long ll;
const ll INF = 1e18;
int n, m;
namespace sub1{
void solve(){
vector<int>a(n), b(n), c(n), d(n);
for(int i = 0; i < n; i++){
cin >> a[i] >> b[i] >> c[i] >> d[i];
}
ll ans = INF;
for(int mask = (1 << n) - 1; mask > -1; mask--){
ll sum = 0;
for(int i = 0; i < n; i++){
if(1 << i & mask){
sum += d[i];
}
}
if(sum < ans){
int pat = -1;
for(int i = 1; i <= m; i++){
int x = i;
for(int j = 0; j < n; j++){
if((1 << j & mask) && a[j] <= x && b[j] >= x){
x = c[j];
}
}
if(pat == -1){
pat = x;
}
else if(pat != x){
sum = -1;
break;
}
}
if(sum != -1){
ans = sum;
}
}
}
cout << (ans == INF ? -1 : ans);
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
cin >> n >> m;
if(n <= 10 && m <= 1000){
sub1::solve();
}
}
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... |