# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
313834 | MKopchev | Restore Array (RMI19_restore) | C++14 | 387 ms | 1012 KiB |
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;
const int nmax=5e3+42;
struct edge
{
int u,v,cost;
};
vector<edge> all;
int n,q;
int dist[nmax];
void bellman()
{
for(int i=1;i<=n;i++)dist[i]=1e9;
for(int t=0;t<=n;t++)
{
for(auto w:all)
if(dist[w.u]+w.cost<dist[w.v])
{
dist[w.v]=dist[w.u]+w.cost;
//cout<<"update "<<w.u<<" "<<w.v<<" "<<w.cost<<endl;
//for(int j=0;j<=n;j++)cout<<dist[j]<<" ";cout<<endl;
}
//for(int j=0;j<=n;j++)cout<<dist[j]<<" ";cout<<endl;
}
for(auto w:all)
if(dist[w.u]+w.cost<dist[w.v])
{
printf("-1\n");
exit(0);
}
for(int i=1;i<=n;i++)
printf("%i ",dist[i]-dist[i-1]);
printf("\n");
}
int main()
{
scanf("%i%i",&n,&q);
for(int i=0;i<n;i++)
{
edge cur;
cur.u=i;
cur.v=i+1;
cur.cost=1;
all.push_back(cur);
cur.u=i+1;
cur.v=i;
cur.cost=0;
all.push_back(cur);
}
for(int i=1;i<=q;i++)
{
edge cur;
int l,r,k,val;
scanf("%i%i%i%i",&l,&r,&k,&val);
l++;
r++;
if(val==0)
{
cur.u=l-1;
cur.v=r;
cur.cost=(r-l+1)-(k+1)+1;
all.push_back(cur);
}
else
{
cur.u=r;
cur.v=l-1;
cur.cost=-((r-l+1)-(k-1));
all.push_back(cur);
}
}
/*
for(auto w:all)
cout<<w.u<<" "<<w.v<<" "<<w.cost<<endl;
*/
bellman();
return 0;
}
Compilation message (stderr)
# | 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... |