#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xx first
#define yy second
#define srt(a) sort(a.begin(),a.end());
#define srtg(a,ll) sort(a.begin(),a.end(),greater<ll>())
#define lb(a,x) lower_bound(a.begin(),a.end(),x)
#define up(a,x) upper_bound(a.begin(),a.end(),x)
#define fnd(a,x) find(a.begin(),a.end(),x)
#define vstart auto startt=chrono::system_clock::now()
#define vend auto endd=chrono::system_clock::now()
#define vvreme chrono::duration<double> vremee=endd-startt
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<ll,ll> pll;
typedef string str;
pii matra[11][1001];
ll n,m;
ll uradi(ll a,ll mask){
ll j=a;
for(ll i=0;i<=m;i++){
if(matra[i][j]==mp(-1LL,-1LL)) continue;
if(((1<<matra[i][j].yy)&mask)>0){
j=matra[i][j].xx;
}
}
return j;
}
bool moze(ll mask){
ll mini=1001;
ll maxi=-1;
for(ll i=1;i<=n;i++){
ll sta=uradi(i,mask);
mini=min(sta,mini);
maxi=max(sta,maxi);
}
if(mini==maxi) return true;
return false;
}
int main()
{
ios;
cin>>m>>n;
vector<ll> niz(m);
for(ll i=0;i<11;i++){
for(ll j=0;j<1001;j++) matra[i][j]=mp(-1,-1);
}
for(ll i=0;i<m;i++){
ll a,b,c,d;
cin>>a>>b>>c>>d;
for(ll k=a;k<=b;k++){
matra[i+1][k]=mp(c,i);
}
niz[i]=d;
}
ll res=LLONG_MAX;
for(ll mask=0;mask<(1<<m);mask++){
ll tren=0;
for(ll j=0;j<m;j++){
if(((1<<j)&mask)>0) tren+=niz[j];
}
if(moze(mask)) res=min(res,tren);
}
if(res==LLONG_MAX) cout<<-1;
else cout<<res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
11 ms |
512 KB |
Output is correct |
5 |
Correct |
18 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
21 ms |
512 KB |
Output is correct |
8 |
Correct |
27 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
11 ms |
512 KB |
Output is correct |
5 |
Correct |
18 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
21 ms |
512 KB |
Output is correct |
8 |
Correct |
27 ms |
512 KB |
Output is correct |
9 |
Runtime error |
1 ms |
768 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
11 ms |
512 KB |
Output is correct |
5 |
Correct |
18 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
21 ms |
512 KB |
Output is correct |
8 |
Correct |
27 ms |
512 KB |
Output is correct |
9 |
Runtime error |
1 ms |
768 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
11 ms |
512 KB |
Output is correct |
5 |
Correct |
18 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
21 ms |
512 KB |
Output is correct |
8 |
Correct |
27 ms |
512 KB |
Output is correct |
9 |
Runtime error |
1 ms |
768 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |