This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
#ifdef duc_debug
#include "bits/debug.h"
#else
#define debug(...)
#endif
const int maxn = 5005;
int n, q;
int f[maxn];
struct info {
int u, v, w;
};
vector<info> edges;
void solve() {
cin >> n >> q;
for(int i = 1; i <= n; ++i) {
edges.push_back({i, i - 1, 1});
edges.push_back({i - 1, i, 0});
}
for(int i = 1; i <= q; ++i) {
int l, r, k, v; cin >> l >> r >> k >> v;
if(!v) {
// at least k zeros
edges.push_back({l, r + 1, -k});
}
else {
// at most k - 1 zeros
edges.push_back({r + 1, l, k - 1});
}
}
memset(f, 0x3f, sizeof(f));
f[0] = 0;
// check neg cycle
for(int ite = 1; ite <= n; ++ite) {
for(auto i:edges) {
int u = i.u, v = i.v;
int w = i.w;
f[u] = min(f[u], f[v] + w);
}
}
for(auto i:edges) {
if(f[i.u] > f[i.v] + i.w) {
cout << -1;
return;
}
}
for(int i = 1; i <= n; ++i) {
cout << (f[i] - f[i - 1] ? 0 : 1) << ' ';
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |