Submission #333317

# Submission time Handle Problem Language Result Execution time Memory
333317 2020-12-05T12:15:58 Z keko37 Restore Array (RMI19_restore) C++14
20 / 100
600 ms 1004 KB
#include<bits/stdc++.h>

using namespace std;

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

const int MAXN = 5005;

int n, m;
int dist[MAXN];
vector <pi> v[MAXN];

bool relax () {
    bool ok = 0;
    for (int i = 0; i <= n + 1; i++) {
        for (auto pp : v[i]) {
            int sus = pp.first, w = pp.second;
            if (dist[sus] > dist[i] + w) {
                dist[sus] = dist[i] + w;
                ok = 1;
            }
        }
    }
    return ok;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        v[i - 1].push_back({i, 1});
        v[i].push_back({i - 1, 0});
    }
    for (int i = 0; i < m; i++) {
        int lef, rig, k, val;
        cin >> lef >> rig >> k >> val;
        lef++; rig++;
        if (val == 0) {
            v[lef - 1].push_back({rig, rig - lef + 1 - k});
        } else {
            v[rig].push_back({lef - 1, k-1 - (rig - lef + 1)});
        }
    }
    for (int i = 0; i <= n; i++) {
        v[n + 1].push_back({i, 0});
    }
    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 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 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 186 ms 1004 KB Output is correct
2 Correct 286 ms 1004 KB Output is correct
3 Correct 5 ms 876 KB Output is correct
4 Correct 321 ms 1004 KB Output is correct
5 Correct 521 ms 1000 KB Output is correct
6 Correct 515 ms 1000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 186 ms 1004 KB Output is correct
2 Correct 286 ms 1004 KB Output is correct
3 Correct 5 ms 876 KB Output is correct
4 Correct 321 ms 1004 KB Output is correct
5 Correct 521 ms 1000 KB Output is correct
6 Correct 515 ms 1000 KB Output is correct
7 Correct 94 ms 1004 KB Output is correct
8 Correct 114 ms 1004 KB Output is correct
9 Correct 100 ms 1000 KB Output is correct
10 Correct 123 ms 1004 KB Output is correct
11 Execution timed out 673 ms 1004 KB Time limit exceeded
12 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 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 186 ms 1004 KB Output is correct
12 Correct 286 ms 1004 KB Output is correct
13 Correct 5 ms 876 KB Output is correct
14 Correct 321 ms 1004 KB Output is correct
15 Correct 521 ms 1000 KB Output is correct
16 Correct 515 ms 1000 KB Output is correct
17 Correct 94 ms 1004 KB Output is correct
18 Correct 114 ms 1004 KB Output is correct
19 Correct 100 ms 1000 KB Output is correct
20 Correct 123 ms 1004 KB Output is correct
21 Execution timed out 673 ms 1004 KB Time limit exceeded
22 Halted 0 ms 0 KB -