Submission #289544

# Submission time Handle Problem Language Result Execution time Memory
289544 2020-09-02T17:56:06 Z TadijaSebez Treatment Project (JOI20_treatment) C++11
0 / 100
3000 ms 5804 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=100050;
const ll inf=9e18;
ll dp[N];
int n,m;
struct project{
	int t,l,r,c;
	project(){}
	project(int a,int b,int d,int e):t(a),l(b),r(d),c(e){}
	bool operator < (project b){
		if(b.l==1)return 0;
		if(l==1)return 1;
		if(r==n)return 0;
		if(b.r==n)return 1;
		return r+t<b.r+b.t;
	}
}pro[N];
int main(){
	scanf("%i %i",&n,&m);
	for(int i=1;i<=m;i++)scanf("%i %i %i %i",&pro[i].t,&pro[i].l,&pro[i].r,&pro[i].c);
	sort(pro+1,pro+1+m);
	ll ans=inf;
	for(int i=1;i<=m;i++){
		if(pro[i].l==1)dp[i]=pro[i].c;
		else dp[i]=inf;
		for(int j=1;j<i;j++){
			bool ok=0;
			if(pro[i].t<pro[j].t){
				int l=pro[i].l+(pro[j].t-pro[i].t);
				if(l<=pro[j].r+1)ok=1;
			}else{
				int r=pro[j].r-(pro[i].t-pro[j].t);
				if(r>=pro[i].l-1)ok=1;
			}
			if(ok)dp[i]=min(dp[i],dp[j]+pro[i].c);
		}
		if(pro[i].r==n)ans=min(ans,dp[i]);
	}
	printf("%lld\n",ans==inf?-1:ans);
	return 0;
}

Compilation message

treatment.cpp: In function 'int main()':
treatment.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |  scanf("%i %i",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~~
treatment.cpp:22:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |  for(int i=1;i<=m;i++)scanf("%i %i %i %i",&pro[i].t,&pro[i].l,&pro[i].r,&pro[i].c);
      |                       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 3066 ms 5804 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3066 ms 5804 KB Time limit exceeded
2 Halted 0 ms 0 KB -