Submission #199044

# Submission time Handle Problem Language Result Execution time Memory
199044 2020-01-28T18:50:53 Z popovicirobert Restore Array (RMI19_restore) C++14
7 / 100
37 ms 1272 KB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define uint unsigned int


using namespace std;

struct Edge {
    int nod, delta, val;
};

int main() {
#ifdef HOME
    ifstream cin("A.in");
    ofstream cout("A.out");
#endif
    int i, n, m;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n >> m;

    vector < vector <Edge> > g(n + 1);
    for(i = 1; i <= m; i++) {
        int l, r, k, val;
        cin >> l >> r >> k >> val;
        l++, r++;
        g[l - 1].push_back({r, r - l + 1 - k + val, val});
        g[r].push_back({l - 1, r - l + 1 - k + val, val});
    }

    for(i = 0; i < n; i++) {
        g[i].push_back({i + 1, 1, 0});
        g[i + 1].push_back({i, 1, 0});
        g[i].push_back({i + 1, 0, 1});
        g[i + 1].push_back({i, 0, 1});
    }

    vector <int> L(n + 1), R(n + 1);
    for(i = 0; i <= n; i++) {
        L[i] = 0, R[i] = i;
    }

    vector <bool> inq(n + 1);
    queue <int> Q;
    Q.push(0), inq[0] = 1;

    auto walk = [&](int l, const Edge &e) {
        int r = e.nod;
        if(l > r) {
            swap(l, r);
        }

        pair <int, int> curl = {L[l], R[l]};
        pair <int, int> curr = {L[r], R[r]};

        if(e.val == 0) {
            L[l] = max(L[l], L[r] - e.delta);
            R[r] = min(R[r], R[l] + e.delta);
        }
        else {
            L[r] = max(L[r], L[l] + e.delta);
            R[l] = min(R[l], R[r] - e.delta);
        }

        if(curl.first != L[l] || curl.second != R[l]) {
            if(inq[l] == 0) {
                inq[l] = 1;
                Q.push(l);
            }
        }

        if(curr.first != L[r] || curr.second != R[r]) {
            if(inq[r] == 0) {
                inq[r] = 1;
                Q.push(r);
            }
        }


    };

    while(Q.size()) {
        int nod = Q.front();
        inq[nod] = 0, Q.pop();

        if(L[nod] > R[nod]) {
            cout << -1;
            return 0;
        }

        for(auto &it : g[nod]) {
            walk(nod, it);
        }
    }

    for(i = 1; i <= n; i++) {
        cout << L[i] - L[i - 1] << " ";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 380 KB Output is correct
8 Correct 5 ms 380 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 1272 KB Output is correct
2 Incorrect 16 ms 1272 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 37 ms 1272 KB Output is correct
2 Incorrect 16 ms 1272 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 380 KB Output is correct
8 Correct 5 ms 380 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 37 ms 1272 KB Output is correct
12 Incorrect 16 ms 1272 KB Output isn't correct
13 Halted 0 ms 0 KB -