Submission #748975

#TimeUsernameProblemLanguageResultExecution timeMemory
748975Dan4LifeTreatment Project (JOI20_treatment)C++17
35 / 100
485 ms355020 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
const int mxM = (int)5e3+10;
const int LINF = (int)1e18;
using pii = pair<int,int>;

int n, m, ans=LINF;
int dis[mxM], vis[mxM];
vector<pii> adj[mxM], v;
struct Project{ int t, l, r, c; } a[mxM];

int dijkstra(vector<pii> v){
	fill(dis,dis+m,LINF); fill(vis,vis+m,0); 
	for(auto [u,w] : v) dis[u]=w;
	for(int i = 0; i < m; i++){
		int mn = LINF, a = -1;
		for(int j = 0; j < m; j++)
			if(!vis[j] and mn>dis[j]) mn=dis[j],a=j;
		if(a==-1) break; vis[a]=1;
		for(auto [b,w]: adj[a])
			if(dis[a]+w < dis[b]) 
				dis[b]=dis[a]+w;
	}
	int d = LINF;
	for(int i = 0; i < m; i++) 
		if(a[i].r==n) d=min(d,dis[i]);
	return d;
}

int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m;
	for(int i = 0; i < m; i++) 
		cin >> a[i].t >> a[i].l >> a[i].r >> a[i].c;
	for(int i = 0; i < m; i++)
		for(int j = 0; j < m; j++)
			if(a[i].r-abs(a[i].t-a[j].t)>=a[j].l-1 and i!=j)
				adj[i].pb({j,a[j].c});
	for(int i = 0; i < m; i++) if(a[i].l==1) v.pb({i,a[i].c});
	ans = dijkstra(v);
	cout << (ans==LINF?-1:ans);
}

Compilation message (stderr)

treatment.cpp: In function 'long long int dijkstra(std::vector<std::pair<long long int, long long int> >)':
treatment.cpp:21:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   21 |   if(a==-1) break; vis[a]=1;
      |   ^~
treatment.cpp:21:20: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   21 |   if(a==-1) break; vis[a]=1;
      |                    ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...