Submission #331099

# Submission time Handle Problem Language Result Execution time Memory
331099 2020-11-27T10:34:04 Z evpipis Restore Array (RMI19_restore) C++11
7 / 100
600 ms 872 KB
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;

const int len = 5005, inf = 1e9;
int dis[len], n, m;
//vector<int> adj[len];

struct edge{
    int a, b, c;

    edge(){}

    edge(int i, int j, int k){
        a = i, b = j, c = k;
    }
};

vector<edge> edg;

void add(int a, int b, int c){
    //adj[a].pb(mp(b, c));
    edg.pb(edge(a, b, c));
}

void bellman(){
    for (int i = 1; i <= n; i++)
        dis[i] = inf;

    for (int rep = 0; rep < n; rep++)
        for (auto e: edg)
            if (dis[e.a]+e.c < dis[e.b])
                dis[e.b] = dis[e.a]+e.c;
        /*for (int u = 0; u <= n; u++)
            for (auto v: adj[u])
                if (dis[u]+v.se < dis[v.fi])
                    dis[v.fi] = dis[u]+v.se;*/
}

bool negative(){
    for (auto e: edg)
        if (dis[e.a]+e.c < dis[e.b])
            return true;
        /*for (auto v: adj[u])
            if (dis[u]+v.se < dis[v.fi])
                return true;*/
    return false;
}

void print(){
    for (int i = n; i >= 1; i--)
        dis[i] = 1-(dis[i]-dis[i-1]);
    for (int i = 1; i <= n; i++)
        printf("%d ", dis[i]);
    printf("\n");
}

int main(){
    scanf("%d %d", &n, &m);

    for (int i = 1; i <= n; i++){
        add(i-1, i, 1);
        add(i, i-1, 0);
    }

    for (int i = 0; i < m; i++){
        int l, r, k, v;
        scanf("%d %d %d %d", &l, &r, &k, &v);
        l++, r++;

        if (v == 0)
            add(r, l-1, -k);
        else
            add(l-1, r, k-1);
    }

    bellman();

    if (negative()){
        printf("-1\n");
        return 0;
    }

    print();
    return 0;
}

Compilation message

restore.cpp: In function 'int main()':
restore.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   64 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
restore.cpp:73:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   73 |         scanf("%d %d %d %d", &l, &r, &k, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 832 KB Output is correct
2 Correct 127 ms 872 KB Output is correct
3 Correct 139 ms 812 KB Output is correct
4 Correct 129 ms 812 KB Output is correct
5 Execution timed out 613 ms 812 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 124 ms 832 KB Output is correct
2 Correct 127 ms 872 KB Output is correct
3 Correct 139 ms 812 KB Output is correct
4 Correct 129 ms 812 KB Output is correct
5 Execution timed out 613 ms 812 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 124 ms 832 KB Output is correct
12 Correct 127 ms 872 KB Output is correct
13 Correct 139 ms 812 KB Output is correct
14 Correct 129 ms 812 KB Output is correct
15 Execution timed out 613 ms 812 KB Time limit exceeded
16 Halted 0 ms 0 KB -