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;
class Q{
public:
long long int l, r, vo, den;
Q(long long int o, long long int d, long long int v, long long int de): l(o), r(d), vo(v), den(de){}
};
int main()
{
long long int m, n;
cin>>m>>n;
vector<Q>a;
for(long long int i=0; i<m; i++)
{
long long int aa, bb, cc, dd;
cin>>aa>>bb>>cc>>dd;
aa--;
bb--;
cc--;
a.push_back(Q(aa, bb, cc, dd));
}
long long int minn=LLONG_MAX;
for(long long int i=0; i<pow(2, m); i++)
{
vector<long long int>comb;
for(long long int j=0; j<m; j++)
{
if(i&(1<<j))
{
comb.push_back(j);
}
}
/*cout<<"kombinbacija\n";
for(int j=0; j<comb.size(); j++)
cout<<comb[j]<<" ";
cout<<endl;*/
bool first=true, kiki=true;
long long int kraj=-1, local_min=INT_MIN;
//bool visited[comb.size()]={};
for(long long int w=0; w<n; w++)
{
long long int curr=w, pari=0;
for(long long int j=0; j<comb.size(); j++)
{
pari+=a[comb[j]].den;
if(a[comb[j]].l<=curr && curr<=a[comb[j]].r)
{
curr=a[comb[j]].vo;
/*if(!visited[j])
{
visited[j]=1;
}*/
}
}
if(first==true)
{
kraj=curr;
first=false;
}
else
{
if(kraj!=curr)
{
kiki=0;
break;
}
else
{
if(pari>local_min)
local_min=pari;
}
}
}
if(kiki)
{
if(local_min<minn)
minn=local_min;
}
//cout<<endl<<local_min<<endl<<"-------------\n";
}
if(minn==LLONG_MAX)
cout<<-1;
else
cout<<minn;
return 0;
}
Compilation message (stderr)
pinball.cpp: In function 'int main()':
pinball.cpp:44:37: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(long long int j=0; j<comb.size(); j++)
| ~^~~~~~~~~~~~
# | 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... |