Submission #568117

#TimeUsernameProblemLanguageResultExecution timeMemory
568117lacitoRestore Array (RMI19_restore)C++14
100 / 100
359 ms1248 KiB
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")

#include "bits/stdc++.h"
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;

#define int long long
#define endl '\n'
#define mod 1000000007
//\
#define mod 1686876991

const int maxn = 1000001;

int dist[maxn];

vector<array<int, 3>> E;

signed main () {
    cin.tie(0)->sync_with_stdio(0);

    int n, m;
    cin >> n >> m;

    for (int i = 0 ; i < m ; i++) {
        int x, y, k, v;
        cin >> x >> y >> k >> v;
        x++,y++;
        int s = y - x + 1;
        if (v == 1) {
            k--;
            E.push_back({x - 1, y, k - s});
        } else {
            E.push_back({y, x - 1, s - k});
        }
    }

    for (int i = 1 ; i <= n ; i++) dist[i] = INT_MAX;

    for (int i = 0 ; i < n ; i++) {
        E.push_back({i, i + 1, 0});
        E.push_back({i + 1, i, 1});
    }

    for (int iter = 0 ; iter < n ; iter++) {
        for (auto [u,v,w] : E) {
            dist[u] = min(dist[u], dist[v] + w);
        }
    }

    bool imp = 0;

    for (auto [u,v,w] : E) {
        if (dist[u] > dist[v] + w) imp = 1;
    }

    if (imp) cout << -1;
    else {
        for (int i = 1 ; i <= n ; i++) {
            cout << (dist[i] > dist[i-1]) << " ";
        }
    }
}

Compilation message (stderr)

restore.cpp:17:1: warning: multi-line comment [-Wcomment]
   17 | //\
      | ^
restore.cpp: In function 'int main()':
restore.cpp:53:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   53 |         for (auto [u,v,w] : E) {
      |                   ^
restore.cpp:60:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   60 |     for (auto [u,v,w] : E) {
      |               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...