Submission #289498

#TimeUsernameProblemLanguageResultExecution timeMemory
289498TadijaSebezTreatment Project (JOI20_treatment)C++11
0 / 100
3080 ms4216 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});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 (stderr)

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);
      |                       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...