# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
313834 | MKopchev | Restore Array (RMI19_restore) | C++14 | 387 ms | 1012 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... |