답안 #198528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198528 2020-01-26T13:45:42 Z Andrei_Cotor Restore Array (RMI19_restore) C++14
7 / 100
600 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]=0;

        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 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 6 ms 424 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 760 KB Output is correct
2 Correct 10 ms 888 KB Output is correct
3 Correct 9 ms 760 KB Output is correct
4 Correct 10 ms 888 KB Output is correct
5 Execution timed out 1049 ms 1016 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 760 KB Output is correct
2 Correct 10 ms 888 KB Output is correct
3 Correct 9 ms 760 KB Output is correct
4 Correct 10 ms 888 KB Output is correct
5 Execution timed out 1049 ms 1016 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 6 ms 424 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 6 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 10 ms 760 KB Output is correct
12 Correct 10 ms 888 KB Output is correct
13 Correct 9 ms 760 KB Output is correct
14 Correct 10 ms 888 KB Output is correct
15 Execution timed out 1049 ms 1016 KB Time limit exceeded
16 Halted 0 ms 0 KB -