Submission #1128833

#TimeUsernameProblemLanguageResultExecution timeMemory
1128833mnbvcxz123Restore Array (RMI19_restore)C++20
100 / 100
267 ms820 KiB
#include <bits/stdc++.h> using namespace std; const int MAX = 1e4 + 5; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int N, M; cin >> N >> M; vector<tuple<int, int, int>> edges; for(int i = 0; i < M; ++i){ int l, r, k, v; cin >> l >> r >> k >> v; ++r; if(v == 0){ edges.emplace_back(l, r, -k); } else{ edges.emplace_back(r, l, k - 1); } } for(int i = 0; i < N; ++i){ edges.emplace_back(i + 1, i, 1); edges.emplace_back(i, i + 1, 0); } const int inf = 1e9; vector<int> f(N + 1, inf); f[0] = 0; for(int rep = 0; rep < N; ++rep){ for(auto [u, v, w] : edges){ if(f[v] > f[u] + w){ f[v] = f[u] + w; } } } for(auto [u, v, w] : edges){ if(f[v] > f[u] + w){ cout << -1 << '\n'; return 0; } } for(int i = 0; i < N; ++i){ if(abs(f[i+1]-f[i])==1)cout<<0<<' '; else cout<<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...