Submission #332271

#TimeUsernameProblemLanguageResultExecution timeMemory
3322712fat2codeRestore Array (RMI19_restore)C++17
100 / 100
479 ms1512 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define all(a) (a).begin(), (a).end() #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #define fr first #define sc second #define int long long #define rc(s) return cout<<s,0 #define rcc(s) cout<<s,exit(0) // restore array rmi 2019 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int nmax = 5005; int n, m, dist[nmax]; struct item{ int l, r, val; }; vector <item> edges; void add_edge(int l, int r, int k, int val){ if(val == 0){ int curr = (r - l + 1) - k; edges.push_back({l - 1, r, curr}); } else{ edges.push_back({r, l - 1,-(r - l + 1 - (k - 1))}); } } bool bellman_ford(){ for(int i=1;i<=n+1;i++){ for(auto it : edges){ if(dist[it.r] > dist[it.l] + it.val){ dist[it.r] = dist[it.l] + it.val; } } } for(auto it : edges){ if(dist[it.r] > dist[it.l] + it.val){ return false; } } return true; } int32_t main(){ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0); // freopen("input.in", "r", stdin); cin >> n >> m; for(int i=1;i<=n;i++){ dist[i] = 1e18; } for(int i=0;i<n;i++){ edges.push_back({i, i+1, 1}); } for(int i=1;i<=n;i++){ edges.push_back({i, i - 1, 0}); } for(int i=1;i<=m;i++){ int l, r, k, val; cin >> l >> r >> k >> val; ++l; ++r; add_edge(l, r, k, val); } if(bellman_ford() == false){ rc(-1); } else{ for(int i=1;i<=n;i++){ cout << dist[i] - dist[i - 1] << ' '; } return 0; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...