Submission #1078442

# Submission time Handle Problem Language Result Execution time Memory
1078442 2024-08-27T17:27:36 Z Abito Treatment Project (JOI20_treatment) C++17
0 / 100
3 ms 1740 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
typedef unsigned long long ull;
using namespace std;
const int N=5005;
int dis[N],n,m;
vector<int> a[N];
vector<pair<int,int>> adj[N];
bool vis[N];
void dijkstra(){
	priority_queue<pair<int,int>> pq;
	for (int i=1;i<=m;i++){
		if (a[i][1]!=1) dis[i]=LLONG_MAX;
		else dis[i]=a[i][3],pq.push({-dis[i],i});
	}
	while (!pq.empty()){
		int x=pq.top().S;
		pq.pop();
		if (vis[x]) continue;
		vis[x]=1;
		for (auto u:adj[x]){
			if (dis[u.F]>dis[x]+u.S){
				dis[u.F]=dis[x]+u.S;
				pq.push({-dis[u.F],u.F});
			}
		}
	}return;
}
int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n>>m;
	for (int i=1;i<=m;i++){
		int t,l,r,c;
		cin>>t>>l>>r>>c;
		a[i]={t,l,r,c};
	}
	sort(a+1,a+1+m);
	for (int i=1;i<=m;i++){
		for (int j=i+1;j<=m;j++){
			int l1=a[i][1],r1=a[i][2];
			if (l1!=1) l1+=a[j][0]-a[i][0];
			if (r1!=n) r1-=a[j][0]-a[i][0];
			if (l1>r1) continue;
			int l2=a[j][1],r2=a[j][2],l3=max(l1,l2),r3=min(r1,r2);
			if (l3<=r3 || r1+1==l2 || r2+1==l1){ 
				adj[i].pb({j,a[j][3]});
				adj[j].pb({i,a[i][3]});
			}
		}
	}
	dijkstra();
	int ans=LLONG_MAX;
	for (int i=1;i<=m;i++) if (a[i][2]==n) ans=min(ans,dis[i]);
	if (ans==LLONG_MAX) ans=-1;
	cout<<ans<<endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 1740 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Incorrect 1 ms 604 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Incorrect 1 ms 604 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 1740 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -