#include<bits/stdc++.h>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
vector < vector < int > > greater(n, vector < int > (n+1, 0));
vector < vector < int > > smaller(n, vector < int > (n+1, n));
for (int i = 0; i < m; i++)
{
int l, r, k, value;
cin >> l >> r >> k >> value;
r++;
int len = r-l;
if (value == 0)
smaller[l][r] = min(smaller[l][r], len - k);
else
greater[l][r] = max(greater[l][r], len - k + 1);
}
for (int i = 0; i < n; i++)
smaller[i][i+1] = min(smaller[i][i+1], 1);
/*
for (int i = 0; i < n; i++)
for (int j = i+1; j <= n; j++)
cerr << i << " -> " << j << " " << smaller[i][j] << " " << greater[i][j] << "\n";
*/
vector < int > mi(n+1, 0);
vector < int > ma(n+1, n);
ma[0] = 0;
for (int i = 0; i < n; i++)
{
int res = 0;
if (mi[i] > ma[i])
{
cout << -1 << "\n";
return 0;
}
for (int j = n; j > i; j--)
{
res = max(res, greater[i][j]);
mi[j] = max(mi[j], mi[i] + res);
ma[j] = min(mi[j], mi[i] + smaller[i][j]);
res = max(res-1, 0);
}
if (res != 0)
{
cout << -1 << "\n";
return 0;
}
}
for (int i = 0; i < n; i++)
for (int j = i+1; j <= n; j++)
{
if (mi[j] > mi[i] + smaller[i][j])
{
cout << -1 << "\n";
return 0;
}
}
vector < int > res;
for (int i = 1; i <= n; i++)
{
if (mi[i] > ma[i])
{
cout << -1 << "\n";
return 0;
}
res.emplace_back(mi[i] - mi[i-1]);
//assert(res.back() == 1 || res.back() == 0);
}
for (auto x : res)
cout << x << " ";
cout << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
195772 KB |
Output is correct |
2 |
Correct |
136 ms |
192660 KB |
Output is correct |
3 |
Correct |
124 ms |
196116 KB |
Output is correct |
4 |
Correct |
119 ms |
191676 KB |
Output is correct |
5 |
Correct |
110 ms |
190360 KB |
Output is correct |
6 |
Correct |
91 ms |
195740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
195772 KB |
Output is correct |
2 |
Correct |
136 ms |
192660 KB |
Output is correct |
3 |
Correct |
124 ms |
196116 KB |
Output is correct |
4 |
Correct |
119 ms |
191676 KB |
Output is correct |
5 |
Correct |
110 ms |
190360 KB |
Output is correct |
6 |
Correct |
91 ms |
195740 KB |
Output is correct |
7 |
Correct |
126 ms |
191648 KB |
Output is correct |
8 |
Correct |
119 ms |
192364 KB |
Output is correct |
9 |
Incorrect |
151 ms |
192976 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |