Submission #272682

# Submission time Handle Problem Language Result Execution time Memory
272682 2020-08-18T13:30:26 Z eohomegrownapps Restore Array (RMI19_restore) C++14
20 / 100
600 ms 1024 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n,m;
int INF = 1e9;

void relaxedges(){
    vector<vector<pair<int,int>>> adjlist(n+1); //node,val
    for (int i = 0; i<m; i++){
        int l,r,k,v;
        cin>>l>>r>>k>>v;
        r++;
        if (v==0){
            //a[i]=l;
            //b[i]=r;
            //c[i]=k-(r-l);
            adjlist[r].push_back({l,r-l-k});
        } else {
            //a[i]=r;
            //b[i]=l;
            //c[i]=(r-l)-k+1;
            adjlist[l].push_back({r,k-1-(r-l)});
        }
    }
    for (int i = 0; i<n; i++){
        //a[m+2*i]=i;
        //b[m+2*i]=i+1;
        //c[m+2*i]=-1;
        adjlist[i+1].push_back({i,1});
        //a[m+2*i+1]=i+1;
        //b[m+2*i+1]=i;
        //c[m+2*i+1]=0;
        adjlist[i].push_back({i+1,0});
    }
    m+=2*n;
    bool works = true;
    vector<int> distances(n+1,INF);
    distances[0]=0;
    vector<int> numpaths(n+1,0);
    vector<bool> inqueue(n+1,false);
    queue<int> q;
    q.push(0);
    while (q.size()>0&&works){
        int f = q.front();
        q.pop();
        inqueue[f]=false;
        for (auto p : adjlist[f]){
            if (distances[p.first]>distances[f]+p.second){
                distances[p.first]=distances[f]+p.second;
                numpaths[p.first]=numpaths[f]+1;
                if (numpaths[p.first]>=n+1){
                    works=false;
                    break;
                }
                if (!inqueue[p.first]){
                    q.push(p.first);
                    inqueue[p.first]=true;
                }
            }
        }
    }
    if (!works){
        cout<<-1<<'\n';
        return;
    }

    /*for (int i = 0; i<=n; i++){
        cout<<distances[i]<<' ';
    }cout<<'\n';*/
    for (int i = 0; i<n; i++){
        cout<<-(distances[i+1]-distances[i])<<' ';
    }cout<<'\n';
}


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n>>m;
    /*if (n<=18){
        subtask1();
    } else {*/
        relaxedges();
    //}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 792 KB Output is correct
2 Correct 6 ms 896 KB Output is correct
3 Correct 6 ms 896 KB Output is correct
4 Correct 6 ms 896 KB Output is correct
5 Correct 516 ms 1016 KB Output is correct
6 Correct 526 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 792 KB Output is correct
2 Correct 6 ms 896 KB Output is correct
3 Correct 6 ms 896 KB Output is correct
4 Correct 6 ms 896 KB Output is correct
5 Correct 516 ms 1016 KB Output is correct
6 Correct 526 ms 1016 KB Output is correct
7 Correct 14 ms 1024 KB Output is correct
8 Correct 14 ms 1024 KB Output is correct
9 Correct 13 ms 1024 KB Output is correct
10 Correct 27 ms 896 KB Output is correct
11 Execution timed out 1092 ms 896 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 5 ms 792 KB Output is correct
12 Correct 6 ms 896 KB Output is correct
13 Correct 6 ms 896 KB Output is correct
14 Correct 6 ms 896 KB Output is correct
15 Correct 516 ms 1016 KB Output is correct
16 Correct 526 ms 1016 KB Output is correct
17 Correct 14 ms 1024 KB Output is correct
18 Correct 14 ms 1024 KB Output is correct
19 Correct 13 ms 1024 KB Output is correct
20 Correct 27 ms 896 KB Output is correct
21 Execution timed out 1092 ms 896 KB Time limit exceeded
22 Halted 0 ms 0 KB -