Submission #289555

#TimeUsernameProblemLanguageResultExecution timeMemory
289555TadijaSebezTreatment Project (JOI20_treatment)C++11
35 / 100
2346 ms524292 KiB
#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});} 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 j,int i){ int delta_t=abs(pro[i].t-pro[j].t); if(delta_t>pro[j].r+1-pro[i].l)return 0; return 1; } 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)AddEdge(0,i); for(int j=1;j<=m;j++)if(i!=j){ if(can_merge(i,j))AddEdge(i,j); if(can_merge(j,i))AddEdge(j,i); } if(pro[i].r==n)AddEdge(i,m+1); } Dijkstra(0,m+1); ll ans=dist[m+1]; printf("%lld\n",ans==inf?-1:ans); return 0; }

Compilation message (stderr)

treatment.cpp: In function 'int main()':
treatment.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |  scanf("%i %i",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~~
treatment.cpp:43:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |  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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...