#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,s,e) for(int i = s; i <= (int)e; ++i)
#define DEC(i,s,e) for(int i = s; i >= (int)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{" << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
#define reach cerr << "LINE: " << __LINE__ << "\n";
#else
#define reach
#define db(x)
#define db2(x,y)
#define db3(a,b,c)
#define dbv(v)
#define dbvp(v)
#define dba(a,ss,ee)
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define g0(x) get<0>(x)
#define g1(x) get<1>(x)
#define g2(x) get<2>(x)
#define g3(x) get<3>(x)
typedef pair <int, int> pi;
typedef tuple<int,int,int> ti3;
typedef tuple<int,int,int,int> ti4;
int rand(int a, int b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (long long)1e18 + 500;
template <typename T> void chmax(T& a, const T b) { a=max(a,b); }
template <typename T> void chmin(T& a, const T b) { a=min(a,b); }
const int MAXN = 100005;
int n,m;
struct item {
int t,l,r,c;
} T[MAXN];
vector<pi> vec;
map<int,multiset<int>> S; // {right diag, cost}
priority_queue<pi,vector<pi>,greater<pi>> pq; // {right diagonal, index}
struct node {
int s,e,m,val;
node *l=nullptr, *r=nullptr;
node(int _s, int _e) {
s=_s;e=_e;
m=floor(((double)s+e)/2);
val=oo;
}
int query(int x, int y) {
if(s==x&&e==y)return val;
if(x>m) return (r?r->query(x,y):oo);
if(y<=m) return (l?l->query(x,y):oo);
else return min(l?l->query(x,m):oo, r?r->query(m+1,y):oo);
}
void update(int x, int nval){
if(s==e){
val=nval;
return;
}
if(x>m){
if(r==nullptr)r=new node(m+1,e);
r->update(x,nval);
} else {
if(l==nullptr)l=new node(s,m);
l->update(x,nval);
}
val=min(l?l->val:oo,r?r->val:oo);
}
}*seg=new node(-2*inf,2*inf);
int ans=oo;
int32_t main()
{
IAMSPEED
cin >> n >> m;
FOR(i,0,m-1) cin >> T[i].t >> T[i].l >> T[i].r >> T[i].c;
FOR(bm,0,(1<<m)-1) {
int cost =0 ;
FOR(j,0,bm-1)if(bm&(1<<j))cost+=T[j].c;
int mxt=0;
FOR(j,0,bm-1)if(bm&(1<<j))chmax(mxt,T[j].t);
set<int> s;
FOR(j,0,bm-1)if(bm&(1<<j)) {
int rl=1;
if(T[j].l != 1)rl=T[j].l+mxt-T[j].t;
int rr=n;
if(T[j].r != n)rr=T[j].r-(mxt-T[j].t);
FOR(x,rl,rr)s.insert(x);
}
if(s.size()==n)chmin(ans,cost);
}
if(ans!=oo)cout<<ans;
else cout<<-1;
return (0-0) ;
}
Compilation message
treatment.cpp: In function 'int32_t main()':
treatment.cpp:100:14: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
100 | if(s.size()==n)chmin(ans,cost);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
3404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
3081 ms |
465860 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
3081 ms |
465860 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
3404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |