#include <bits/stdc++.h>
#define ll long long
#define fast cin.tie(0);cout.tie(0);
#define order ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);
#define pb push_back
using namespace std;
int n,m,a[200009],b[200009],c[200009];
ll d[200009],ans;
ll mxv=1e9;
ll dp[29][69][69];
ll bt(int x,int l,int r)
{
if(x==-1)
{
if(l==0&&r==n)return 0;
else return mxv;
}
if(dp[x][l][r]!=-1)return dp[x][l][r];
ll &ret=dp[x][l][r];
ret=mxv;
ret=bt(x-1,l,r);
if(l<=c[x]&&c[x]<=r)ret=min(ret,d[x]+bt(x-1,min(l,a[x]),max(r,b[x])));
return ret;
}
vector<int>v;
map<int,int>mp;
int main()
{
fast order
mxv*=mxv;
cin>>m>>n;
memset(dp,-1,sizeof(dp));
for(int i=0;i<m;i++)cin>>a[i]>>b[i]>>c[i]>>d[i];
for(int i=0;i<m;i++)
{
v.push_back(a[i]);
v.push_back(b[i]);
v.push_back(c[i]);
}
v.push_back(n);
sort(v.begin(),v.end());
for(int i=0,j=0;i<v.size();i++)
{
int x=v[i];
if(i)
{
if(x==v[i-1])continue;
}
mp[v[i]]=j;
j++;
}
for(int i=0;i<m;i++)
{
a[i]=mp[a[i]];
b[i]=mp[b[i]];
c[i]=mp[c[i]];
}
n=mp[n];
ans=mxv;
for(int i=0;i<n;i++)
{
//cout<<ans<<"\n";
ans=min(ans,bt(m-1,i,i));
}
if(ans==mxv)cout<<-1;
else cout<<ans;
}
Compilation message
pinball.cpp: In function 'int main()':
pinball.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i=0,j=0;i<v.size();i++)
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1408 KB |
Output is correct |
2 |
Correct |
1 ms |
1408 KB |
Output is correct |
3 |
Correct |
1 ms |
1408 KB |
Output is correct |
4 |
Correct |
1 ms |
1408 KB |
Output is correct |
5 |
Correct |
1 ms |
1408 KB |
Output is correct |
6 |
Correct |
1 ms |
1408 KB |
Output is correct |
7 |
Incorrect |
1 ms |
1408 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1408 KB |
Output is correct |
2 |
Correct |
1 ms |
1408 KB |
Output is correct |
3 |
Correct |
1 ms |
1408 KB |
Output is correct |
4 |
Correct |
1 ms |
1408 KB |
Output is correct |
5 |
Correct |
1 ms |
1408 KB |
Output is correct |
6 |
Correct |
1 ms |
1408 KB |
Output is correct |
7 |
Incorrect |
1 ms |
1408 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1408 KB |
Output is correct |
2 |
Correct |
1 ms |
1408 KB |
Output is correct |
3 |
Correct |
1 ms |
1408 KB |
Output is correct |
4 |
Correct |
1 ms |
1408 KB |
Output is correct |
5 |
Correct |
1 ms |
1408 KB |
Output is correct |
6 |
Correct |
1 ms |
1408 KB |
Output is correct |
7 |
Incorrect |
1 ms |
1408 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1408 KB |
Output is correct |
2 |
Correct |
1 ms |
1408 KB |
Output is correct |
3 |
Correct |
1 ms |
1408 KB |
Output is correct |
4 |
Correct |
1 ms |
1408 KB |
Output is correct |
5 |
Correct |
1 ms |
1408 KB |
Output is correct |
6 |
Correct |
1 ms |
1408 KB |
Output is correct |
7 |
Incorrect |
1 ms |
1408 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |