Submission #238486

#TimeUsernameProblemLanguageResultExecution timeMemory
238486SortingRestore Array (RMI19_restore)C++14
100 / 100
378 ms1088 KiB
#include <bits/stdc++.h> using namespace std; const int k_N = 5000 + 3; const int k_M = 10000 + 3; const int k_Inf = 1e9 + 3; int n, m; vector<array<int, 3>> edges; int prefix[k_N]; bool bellman_ford(){ prefix[0] = 0; for(int i = 1; i <= n; ++i) prefix[i] = k_Inf; for(int i = 0; i < n; ++i){ for(auto &edge: edges){ int new_prefix = prefix[edge[0]] + edge[2]; prefix[edge[1]] = min(new_prefix, prefix[edge[1]]); } } for(auto &edge: edges){ int new_prefix = prefix[edge[0]] + edge[2]; if(new_prefix < prefix[edge[1]]) return false; } return true; } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for(int i = 1; i <= n; ++i){ edges.push_back({i - 1, i, 1}); edges.push_back({i, i - 1, 0}); } for(int i = 0; i < m; ++i){ int l, r, k, value; cin >> l >> r >> k >> value; l++, r++; if(value == 0) edges.push_back({l - 1, r, (r - l + 1) - k}); else if(value == 1) edges.push_back({r, l - 1, -((r - l + 1) - k + 1)}); } if(!bellman_ford()){ cout << "-1\n"; return 0; } for(int i = n; i >= 1; --i) prefix[i] -= prefix[i - 1]; for(int i = 1; i <= n; ++i) cout << prefix[i] << " "; cout << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...