Submission #643748

#TimeUsernameProblemLanguageResultExecution timeMemory
643748k_balint31415Restore Array (RMI19_restore)C++14
100 / 100
354 ms1096 KiB
#include <bits/stdc++.h> using namespace std; const int c=5005; const int inf=1e8; struct edge{ int a,b,val; edge(int a, int b, int val):a(a),b(b),val(val){} }; vector<edge> edges; int dist[c]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n,m; cin>>n>>m; for(int i=1;i<=m;i++){ int l,r,k,val; cin>>l>>r>>k>>val; if(val){ edges.push_back(edge(r+1,l,-(r+1)+l+k-1)); } else{ edges.push_back(edge(l,r+1,r+1-l-k)); } } for(int i=1;i<=n;i++){ edges.push_back(edge(i,i-1,0)); edges.push_back(edge(i-1,i,1)); } dist[0]=0; for(int i=1;i<=n;i++){ dist[i]=inf; } bool neg=0; for(int i=0;i<n;i++){ neg=0; for(int j=0;j<edges.size();j++){ if(dist[edges[j].a]<inf){ if(dist[edges[j].b]>dist[edges[j].a]+edges[j].val){ dist[edges[j].b]=max(-inf,dist[edges[j].a]+edges[j].val); neg=1; } } } } if(neg){ cout << -1 << endl; return 0; } for(int i=1;i<=n;i++){ cout << dist[i]-dist[i-1] << ' '; } cout << endl; }

Compilation message (stderr)

restore.cpp: In function 'int main()':
restore.cpp:43:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for(int j=0;j<edges.size();j++){
      |                     ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...