This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
struct mazan{
int a,b,cost;
};
vector <mazan> much;
int dist[5001];
int main()
{
int n,m,i,l,r,k,val;
cin>>n>>m;
for(i=0;i<=n;i++)
dist[i]=1e9;
dist[0]=0;
for(i=0;i<n;i++)
much.push_back({i,i+1,1});
for(i=1;i<=n;i++)
much.push_back({i,i-1,0});
for(i=1;i<=m;i++)
{
cin>>l>>r>>k>>val;
if(val==1)
much.push_back({r+1,l,-((r-l+1)-(k-1))});
else
much.push_back({l,r+1,(r-l+1)-k});
}
for(i=1;i<=n+1;i++)
for(auto [a,b,cost]:much)
if(dist[b]>dist[a]+cost)
dist[b]=dist[a]+cost;
for(auto [a,b,cost]:much)
if(dist[b]>dist[a]+cost)
{
cout<<-1;
return 0;
}
for(i=1;i<=n;i++)
cout<<dist[i]-dist[i-1]<<" ";
return 0;
}
Compilation message (stderr)
restore.cpp: In function 'int main()':
restore.cpp:28:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
28 | for(auto [a,b,cost]:much)
| ^
restore.cpp:31:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
31 | for(auto [a,b,cost]:much)
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |