답안 #198518

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198518 2020-01-26T13:22:34 Z Andrei_Cotor Restore Array (RMI19_restore) C++14
0 / 100
10 ms 1016 KB
#include<iostream>
#include<vector>
#include<deque>

using namespace std;

int Nr0[5005];  //cate valori 0 am in [1,i]
int NrInQ[5005],InQ[5005];
vector<pair<int,int> > A[5005]; //(x,y,c) = Nr0[y]<=Nr0[x]+c

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n,m;
    cin>>n>>m;

    for(int i=1; i<=m; i++)
    {
        int st,dr,k,val;
        cin>>st>>dr>>k>>val;

        st++;
        dr++;

        if(val==0)
            A[dr].push_back({st-1,-k});
        else
            A[st-1].push_back({dr,k-1});
    }

    for(int i=1; i<=n; i++)
    {
        A[i-1].push_back({i,1});
        A[i].push_back({i-1,0});

        Nr0[i]=1000000000;
    }

    deque<int> Q;
    Q.push_back(0);
    InQ[0]=1;
    NrInQ[0]=1;
    while(!Q.empty())
    {
        int nod=Q.front();
        Q.pop_front();
        InQ[nod]=1;

        for(auto other:A[nod])
        {
            if(Nr0[other.first]>Nr0[nod]+other.second)
            {
                Nr0[other.first]=Nr0[nod]+other.second;

                if(InQ[other.first])
                    continue;

                if(NrInQ[other.first]>n)
                {
                    cout<<"-1\n";
                    return 0;
                }

                Q.push_back(other.first);
                InQ[other.first]=1;
                NrInQ[other.first]++;
            }
        }
    }

    for(int i=1; i<=n; i++)
    {
        if(Nr0[i]!=Nr0[i-1])
            cout<<"0 ";
        else
            cout<<"1 ";
    }
    cout<<"\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1016 KB Output is correct
2 Correct 10 ms 1016 KB Output is correct
3 Correct 10 ms 1016 KB Output is correct
4 Incorrect 10 ms 1016 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1016 KB Output is correct
2 Correct 10 ms 1016 KB Output is correct
3 Correct 10 ms 1016 KB Output is correct
4 Incorrect 10 ms 1016 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -