Submission #198533

# Submission time Handle Problem Language Result Execution time Memory
198533 2020-01-26T13:54:56 Z Andrei_Cotor Restore Array (RMI19_restore) C++14
7 / 100
600 ms 888 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]=0;

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

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

                if(InQ[other.first])
                    continue;

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

    for(int i=1; i<=n; i++)
    {
        if(Nr0[i]!=Nr0[i-1])
            cout<<"0 ";
        else
            cout<<"1 ";
    }
    cout<<"\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 760 KB Output is correct
2 Correct 9 ms 888 KB Output is correct
3 Correct 10 ms 812 KB Output is correct
4 Correct 10 ms 760 KB Output is correct
5 Execution timed out 782 ms 888 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 760 KB Output is correct
2 Correct 9 ms 888 KB Output is correct
3 Correct 10 ms 812 KB Output is correct
4 Correct 10 ms 760 KB Output is correct
5 Execution timed out 782 ms 888 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 9 ms 760 KB Output is correct
12 Correct 9 ms 888 KB Output is correct
13 Correct 10 ms 812 KB Output is correct
14 Correct 10 ms 760 KB Output is correct
15 Execution timed out 782 ms 888 KB Time limit exceeded
16 Halted 0 ms 0 KB -