This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
int m,n,rez=1e18;
int a[205],b[205],c[205],d[205];
bool func(vector<int> uredi){
int topcinja[n+1];
for (int i=1;i<=n;i++)
topcinja[i]=1;
for (auto x:uredi){
for (int i=a[x];i<=b[x];i++)
if (topcinja[i]==1)
topcinja[i]=0, topcinja[c[x]]=1;
}
int br=0;
for (int i=1;i<=n;i++){
if (topcinja[i]) br++;
}
if (br==1) return true;
return false;
}
void f(int red, int cena, vector<int> zemeni){
if (red==m+1) {
if (func(zemeni)) rez=min(rez,cena);
return;
}
f(red+1,cena,zemeni);
zemeni.push_back(red);
f(red+1, cena+d[red], zemeni);
}
int32_t main()
{
cin >> m >> n;
for (int i=1;i<=m;i++){
cin >> a[i] >> b[i] >> c[i] >> d[i];
}
f(1,0,{});
if (rez==1e18) cout << -1;
else cout << rez;
return 0;
}
# | 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... |