Submission #333323

# Submission time Handle Problem Language Result Execution time Memory
333323 2020-12-05T13:31:41 Z keko37 Restore Array (RMI19_restore) C++14
100 / 100
346 ms 748 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long llint;
typedef pair <int, int> pi;

const int MAXN = 5005;
const int MAXM = 10005;

int n, m;
int from[MAXM], to[MAXM], w[MAXM];
int dist[MAXN];

bool relax () {
    bool ok = 0;
    for (int i = 0; i < m; i++) {
        if (dist[to[i]] > dist[from[i]] + w[i]) {
            dist[to[i]] = dist[from[i]] + w[i];
            ok = 1;
        }
    }
    for (int i = 1; i <= n; i++) {
        if (dist[i] < dist[i - 1]) {
            dist[i - 1] = dist[i];
            ok = 1;
        }
        if (dist[i] > dist[i - 1] + 1) {
            dist[i] = dist[i - 1] + 1;
            ok = 1;
        }
    }
    return ok;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int lef, rig, k, val;
        cin >> lef >> rig >> k >> val;
        lef++; rig++;
        if (val == 0) {
            from[i] = lef - 1; to[i] = rig; w[i] = rig - lef + 1 - k;
        } else {
            from[i] = rig; to[i] = lef - 1; w[i] = k-1 - (rig - lef + 1);
        }
    }
    for (int i = 0; i < n + 1; i++) {
        if (!relax()) break;
    }
    if (relax()) {
        cout << -1;
        return 0;
    }
    for (int i = 1; i <= n; i++) {
        cout << dist[i] - dist[i - 1] << " ";
    }
    return 0;
}
# 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 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 620 KB Output is correct
2 Correct 86 ms 492 KB Output is correct
3 Correct 4 ms 492 KB Output is correct
4 Correct 97 ms 492 KB Output is correct
5 Correct 304 ms 532 KB Output is correct
6 Correct 298 ms 532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 620 KB Output is correct
2 Correct 86 ms 492 KB Output is correct
3 Correct 4 ms 492 KB Output is correct
4 Correct 97 ms 492 KB Output is correct
5 Correct 304 ms 532 KB Output is correct
6 Correct 298 ms 532 KB Output is correct
7 Correct 29 ms 620 KB Output is correct
8 Correct 34 ms 492 KB Output is correct
9 Correct 29 ms 492 KB Output is correct
10 Correct 37 ms 492 KB Output is correct
11 Correct 340 ms 620 KB Output is correct
12 Correct 346 ms 492 KB Output is correct
13 Correct 29 ms 620 KB Output is correct
14 Correct 11 ms 680 KB Output is correct
15 Correct 21 ms 620 KB Output is correct
16 Correct 82 ms 620 KB Output is correct
# 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 1 ms 364 KB Output is correct
11 Correct 60 ms 620 KB Output is correct
12 Correct 86 ms 492 KB Output is correct
13 Correct 4 ms 492 KB Output is correct
14 Correct 97 ms 492 KB Output is correct
15 Correct 304 ms 532 KB Output is correct
16 Correct 298 ms 532 KB Output is correct
17 Correct 29 ms 620 KB Output is correct
18 Correct 34 ms 492 KB Output is correct
19 Correct 29 ms 492 KB Output is correct
20 Correct 37 ms 492 KB Output is correct
21 Correct 340 ms 620 KB Output is correct
22 Correct 346 ms 492 KB Output is correct
23 Correct 29 ms 620 KB Output is correct
24 Correct 11 ms 680 KB Output is correct
25 Correct 21 ms 620 KB Output is correct
26 Correct 82 ms 620 KB Output is correct
27 Correct 6 ms 620 KB Output is correct
28 Correct 6 ms 620 KB Output is correct
29 Correct 7 ms 620 KB Output is correct
30 Correct 7 ms 620 KB Output is correct
31 Correct 5 ms 620 KB Output is correct
32 Correct 6 ms 620 KB Output is correct
33 Correct 319 ms 620 KB Output is correct
34 Correct 322 ms 748 KB Output is correct
35 Correct 8 ms 620 KB Output is correct
36 Correct 6 ms 620 KB Output is correct