Submission #940573

#TimeUsernameProblemLanguageResultExecution timeMemory
940573MackerRestore Array (RMI19_restore)C++14
100 / 100
106 ms1368 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll typedef pair<int, int> pii; #define all(v) v.begin(), v.end() #define FOR(i, n) for (int i = 0; i < n; i++) #define inf LLONG_MAX/2 #define fi first #define se second //#pragma GCC optimize("Ofast") //#pragma GCC target("avx2") vector<vector<pii>> adj; vector<int> dist; int n; /* bool SSSP(int s){ dist.assign(n, inf); dist[s] = 0; int upd = -1; FOR(it, n){ upd = -1; FOR(a, n) for (auto &[b, c] : adj[a]) { if(dist[a] == inf) continue; if(dist[b] > dist[a] + c){ dist[b] = dist[a] + c; upd = b; } } } if(upd != -1) return false; else return true; } */ bool spfa(int s) { /// Shortest Path Faster Algorithm vector<bool> inq(n); vector<int> cnt(n); dist.resize(n); for(int i=0; i<n; i++) { dist[i] = inf; cnt[i] = 0; inq[i] = 0; } queue<int> q; dist[s] = 0; q.push(s); inq[s] = 1; while (!q.empty()) { int v = q.front(); q.pop(); inq[v] = 0; for(auto e : adj[v]) { int u = e.fi, w = e.se; if(dist[v] + w < dist[u]) { dist[u] = dist[v] + w; if(dist[u] < 0 ) return false; /// optimization for TLE. if(!inq[u]) { q.push(u); inq[u] = 1; cnt[u]++; if(cnt[u]>n) return false; } } } } return true; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int m; cin >> n >> m; adj.resize(n + 2); FOR(i, m){ int l, r, k, val; cin >> l >> r >> k >> val; r++; if(val == 0){ adj[l].push_back({r, (r - l) - k}); } else{ adj[r].push_back({l, k - r + l - 1}); } } FOR(i, n){ adj[i].push_back({i + 1, 1}); adj[i + 1].push_back({i, 0}); } n++; if(!spfa(0)){ cout << -1 << endl; } else{ FOR(i, n-1){ if(dist[i] < dist[i + 1]) cout << 1; else cout << 0; cout << " "; } cout << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...