Submission #1041269

# Submission time Handle Problem Language Result Execution time Memory
1041269 2024-08-01T19:57:53 Z VMaksimoski008 Restore Array (RMI19_restore) C++17
0 / 100
93 ms 884 KB
#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;

signed main() {
    int n, m;
    cin >> n >> m;

    vector<array<int, 3> > edges;
    for(int i=0; i<m; i++) {
        int l, r, k, val;
        cin >> l >> r >> k >> val; l++; r++;

        if(val == 0) {
            //ako k-ti element e 0, togas sigurno prvite k elemnti se 0
            //pref[r] - pref[l-1] <= (r - l + 1) - k (ako site drugi se 1)
            edges.push_back({ l - 1, r, r - l + 1 - k});
        } else {
            //ako k-ti element e 1, togas sigurno narednite elementi se 1
            // pref[r] - pref[l-1] >= (r - l + 1) - k - 1 = r - l - k
            // pref[l-1] - pref[r] <= l + k - r
            edges.push_back({ r, l - 1, -r + l - 1 + k - 1 });
        }
    }

    //pref[i] - pref[i-1] <= 1
    //pref[i+1] - pref[i] >= 0
    //pref[i] - pref[i+1] <= 0
    for(int i=1; i<=n; i++) edges.push_back({ i-1, i, 1 });
    for(int i=1; i<=n; i++) edges.push_back({ i, i-1, 0 });

    vector<ll> dist(n+1, 1e9); dist[0] = 0;
    for(int i=1; i<n; i++)
        for(auto &[u, v, w] : edges) dist[v] = min(dist[v], dist[u] + w);

    for(auto &[u, v, w] : edges) {
        if(dist[v] > dist[u] + w) {
            cout << -1 << '\n';
            return 0;
        }
    }

    vector<int> ans(n+1);   
    for(int i=2; i<=n; i++) {
        if(dist[i+1] > dist[i]) ans[i] = 1;
        else ans[i] = 0;
    }
    for(int i=1; i<=n; i++) cout << ans[i] << " ";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 93 ms 884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 93 ms 884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -