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;
const int N = 20300;
int f[N], t[N], w[N];
int sz;
int d[N];
int main()
{
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++)
{
int l, r, k, v;
cin >> l >> r >> k >> v;
r++;
if (v == 0)
{
// k-th = zero, at most len-k ones
f[sz] = l;
t[sz] = r;
w[sz] = r - l - k;
sz++;
}
else
{
// k-th = one, at least len - k + 1 ones
f[sz] = r;
t[sz] = l;
w[sz] = -(r - l - k + 1);
sz++;
}
}
for (int i = 0; i < n; i++)
{
f[sz] = i;
t[sz] = i + 1;
w[sz] = 1;
sz++;
}
for (int i = 1; i <= n; i++)
{
d[i] = 1e9;
f[sz] = i;
t[sz] = i - 1;
w[sz] = 0;
sz++;
}
for (int i = 0; i <= n; i++)
{
for (int j = 0; j < sz; j++)
{
if (d[f[j]] + w[j] < d[t[j]])
{
d[t[j]] = d[f[j]] + w[j];
}
}
}
for (int j = 0; j < sz; j++)
{
if (d[f[j]] + w[j] < d[t[j]])
{
cout << -1;
return 0;
}
}
for (int i = 1; i <= n; i++)
{
cout << d[i] - d[i - 1] << " ";
}
}
# | 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... |