Submission #331100

# Submission time Handle Problem Language Result Execution time Memory
331100 2020-11-27T10:40:04 Z evpipis Restore Array (RMI19_restore) C++11
0 / 100
600 ms 876 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<ii> adj[len];

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

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

    int rep = 0;
    while (rep < n){
        bool upd = false;
        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, upd = true;

        if (!upd) break;
        rep++;
    }

    return (rep <= n);
}

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);
    }

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

    print();
    return 0;
}

Compilation message

restore.cpp: In function 'int main()':
restore.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
restore.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   55 |         scanf("%d %d %d %d", &l, &r, &k, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Incorrect 1 ms 492 KB Integer 6 violates the range [-1, 1]
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 748 KB Output is correct
2 Correct 6 ms 748 KB Output is correct
3 Correct 6 ms 748 KB Output is correct
4 Correct 8 ms 748 KB Output is correct
5 Execution timed out 621 ms 876 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 748 KB Output is correct
2 Correct 6 ms 748 KB Output is correct
3 Correct 6 ms 748 KB Output is correct
4 Correct 8 ms 748 KB Output is correct
5 Execution timed out 621 ms 876 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Incorrect 1 ms 492 KB Integer 6 violates the range [-1, 1]
6 Halted 0 ms 0 KB -