Submission #423744

# Submission time Handle Problem Language Result Execution time Memory
423744 2021-06-11T12:15:18 Z errorgorn Treatment Project (JOI20_treatment) C++17
0 / 100
1471 ms 3980 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define endl '\n'

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back

#define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);s<e?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,k;

struct E{
	int l,r;
	int t;
	int c;
};
vector<E> v;

ll memo[5005];

int main(){
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(false);
	
	cin>>n>>k;
	
	int a,b,c,d;
	rep(x,0,k){
		cin>>a>>b>>c>>d;
		v.pub({b,c,a,d});
	}
	
	sort(all(v),[](E i,E j){
		if (i.l==1) return true;
		if (j.l==1) return false;
		
		return i.l-i.t < j.l-j.t;
	});
	
	//for (auto &it:v) cout<<it.l<<" "<<it.r<<" "<<it.t<<endl;
	
	memset(memo,63,sizeof(memo));
	
	ll ans=1e18;
	
	rep(x,0,k){
		if (v[x].l==1) memo[x]=0;
		memo[x]+=v[x].c;
		
		rep(y,x+1,k){
			if (v[x].t<=v[y].t && v[x].r-(v[y].t-v[x].t)>=v[y].l) memo[y]=min(memo[y],memo[x]);
			if (v[y].t<v[x].t && v[y].l+(v[x].t-v[y].t)<=v[x].r) memo[y]=min(memo[y],memo[x]);
		}
		
		if (v[x].r==n) ans=min(ans,memo[x]);
	}
	
	if (ans==1e18) cout<<"-1"<<endl;
	else cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1471 ms 3980 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1471 ms 3980 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -