답안 #289498

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
289498 2020-09-02T17:12:39 Z TadijaSebez 치료 계획 (JOI20_treatment) C++11
0 / 100
3000 ms 4216 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pb push_back
const int N=100050;
const ll inf=9e18;
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){return l+r<b.l+b.r||(l+r==b.l+b.r&&t<b.t);}
}pro[N];
vector<pii> E[N];
void AddEdge(int u,int v){E[u].pb({v,pro[v].c});E[v].pb({u,pro[u].c});}
ll dist[N];
void Dijkstra(int s,int t){
	priority_queue<pair<ll,int>> pq;
	pq.push({0,s});
	for(int i=s+1;i<=t;i++)dist[i]=inf;
	while(pq.size()){
		ll d=-pq.top().first;
		int u=pq.top().second;
		pq.pop();
		if(dist[u]!=d)continue;
		for(auto e:E[u]){
			int v,w;tie(v,w)=e;
			if(dist[v]>dist[u]+w){
				dist[v]=dist[u]+w;
				pq.push({-dist[v],v});
			}
		}
	}
}
int n,m;
bool can_merge(int i,int j){
	if(pro[i].t>pro[j].t)swap(i,j);
	int dt=pro[j].t-pro[i].t;
	int l=pro[i].l+dt,r=pro[i].r-dt;
	if(pro[i].l==1)l=1;
	if(pro[i].r==n)r=n;
	if(max(l,pro[j].l)<=min(r,pro[j].r))return 1;
	return 0;
}
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);
	for(int i=1;i<=m;i++){
		if(pro[i].l==1)E[0].pb({i,pro[i].c});
		for(int j=1;j<i;j++){
			if(can_merge(i,j))AddEdge(i,j);
		}
		if(pro[i].r==n)E[i].pb({m+1,0});
	}
	Dijkstra(0,m+1);
	ll ans=dist[m+1];
	printf("%lld\n",ans==inf?-1:ans);
	return 0;
}

Compilation message

treatment.cpp: In function 'int main()':
treatment.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |  scanf("%i %i",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~~
treatment.cpp:47:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |  for(int i=1;i<=m;i++)scanf("%i %i %i %i",&pro[i].t,&pro[i].l,&pro[i].r,&pro[i].c);
      |                       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3080 ms 4216 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Incorrect 2 ms 2688 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Incorrect 2 ms 2688 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3080 ms 4216 KB Time limit exceeded
2 Halted 0 ms 0 KB -