Submission #643748

# Submission time Handle Problem Language Result Execution time Memory
643748 2022-09-22T21:41:41 Z k_balint31415 Restore Array (RMI19_restore) C++14
100 / 100
354 ms 1096 KB
#include <bits/stdc++.h>
using namespace std;
const int c=5005;
const int inf=1e8;

struct edge{
    int a,b,val;
    edge(int a, int b, int val):a(a),b(b),val(val){}
};

vector<edge> edges;
int dist[c];

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

    int n,m; cin>>n>>m;
    for(int i=1;i<=m;i++){
        int l,r,k,val;
        cin>>l>>r>>k>>val;
        if(val){
            edges.push_back(edge(r+1,l,-(r+1)+l+k-1));
        }
        else{
            edges.push_back(edge(l,r+1,r+1-l-k));
        }
    }

    for(int i=1;i<=n;i++){
        edges.push_back(edge(i,i-1,0));
        edges.push_back(edge(i-1,i,1));
    }

    dist[0]=0;
    for(int i=1;i<=n;i++){
        dist[i]=inf;
    }

    bool neg=0;
    for(int i=0;i<n;i++){
        neg=0;
        for(int j=0;j<edges.size();j++){
            if(dist[edges[j].a]<inf){
                if(dist[edges[j].b]>dist[edges[j].a]+edges[j].val){
                    dist[edges[j].b]=max(-inf,dist[edges[j].a]+edges[j].val);
                    neg=1;
                }
            }
        }
    }

    if(neg){
        cout << -1 << endl;
        return 0;
    }

    for(int i=1;i<=n;i++){
        cout << dist[i]-dist[i-1] << ' ';
    }
    cout << endl;
}

Compilation message

restore.cpp: In function 'int main()':
restore.cpp:43:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for(int j=0;j<edges.size();j++){
      |                     ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 916 KB Output is correct
2 Correct 104 ms 916 KB Output is correct
3 Correct 102 ms 916 KB Output is correct
4 Correct 98 ms 916 KB Output is correct
5 Correct 301 ms 908 KB Output is correct
6 Correct 319 ms 916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 916 KB Output is correct
2 Correct 104 ms 916 KB Output is correct
3 Correct 102 ms 916 KB Output is correct
4 Correct 98 ms 916 KB Output is correct
5 Correct 301 ms 908 KB Output is correct
6 Correct 319 ms 916 KB Output is correct
7 Correct 101 ms 916 KB Output is correct
8 Correct 102 ms 916 KB Output is correct
9 Correct 131 ms 972 KB Output is correct
10 Correct 103 ms 916 KB Output is correct
11 Correct 321 ms 916 KB Output is correct
12 Correct 354 ms 912 KB Output is correct
13 Correct 111 ms 916 KB Output is correct
14 Correct 103 ms 916 KB Output is correct
15 Correct 110 ms 908 KB Output is correct
16 Correct 139 ms 912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 100 ms 916 KB Output is correct
12 Correct 104 ms 916 KB Output is correct
13 Correct 102 ms 916 KB Output is correct
14 Correct 98 ms 916 KB Output is correct
15 Correct 301 ms 908 KB Output is correct
16 Correct 319 ms 916 KB Output is correct
17 Correct 101 ms 916 KB Output is correct
18 Correct 102 ms 916 KB Output is correct
19 Correct 131 ms 972 KB Output is correct
20 Correct 103 ms 916 KB Output is correct
21 Correct 321 ms 916 KB Output is correct
22 Correct 354 ms 912 KB Output is correct
23 Correct 111 ms 916 KB Output is correct
24 Correct 103 ms 916 KB Output is correct
25 Correct 110 ms 908 KB Output is correct
26 Correct 139 ms 912 KB Output is correct
27 Correct 100 ms 916 KB Output is correct
28 Correct 99 ms 916 KB Output is correct
29 Correct 107 ms 916 KB Output is correct
30 Correct 142 ms 916 KB Output is correct
31 Correct 95 ms 912 KB Output is correct
32 Correct 106 ms 1096 KB Output is correct
33 Correct 320 ms 916 KB Output is correct
34 Correct 311 ms 916 KB Output is correct
35 Correct 106 ms 984 KB Output is correct
36 Correct 104 ms 904 KB Output is correct