#include <bits/stdc++.h>
// author: aykhn
using namespace std;
const int MXN = 5e3 + 5;
int n, m;
vector<array<int, 3>> ed;
int dist[MXN];
int add(int a, int b)
{
return a + b;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 0; i < n; i++)
{
ed.push_back({i, add(i, 1), 1});
ed.push_back({add(i, 1), i, 0});
}
for (int i = 1; i <= n; i++) dist[i] = add(n, 10);
while (m--)
{
int l, r, k, v;
cin >> l >> r >> k >> v;
r++;
int sz = r - l;
if (v == 1)
{
int mx = sz;
int mn = sz - k + 1;
ed.push_back({l, r, mx});
ed.push_back({r, l, (int)(-mn)});
}
else
{
int mn = 0;
int mx = sz - k;
ed.push_back({l, r, mx});
ed.push_back({r, l, (int)(-mn)});
}
}
bool f = 0;
for (int i = 1; i <= n + 1; i++)
{
f = 0;
for (const array<int, 3> &x : ed)
{
if (add(dist[x[0]], x[2]) < dist[x[1]])
{
f = 1;
dist[x[1]] = add(dist[x[0]], x[2]);
}
}
}
if (f)
{
cout << -1 << '\n';
return 0;
}
for (int i = 1; i <= n; i++)
{
cout << dist[i] - dist[i - 1] << ' ';
}
cout << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
124 ms |
924 KB |
Output is correct |
2 |
Correct |
116 ms |
936 KB |
Output is correct |
3 |
Correct |
119 ms |
856 KB |
Output is correct |
4 |
Correct |
117 ms |
1048 KB |
Output is correct |
5 |
Correct |
334 ms |
1012 KB |
Output is correct |
6 |
Correct |
365 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
124 ms |
924 KB |
Output is correct |
2 |
Correct |
116 ms |
936 KB |
Output is correct |
3 |
Correct |
119 ms |
856 KB |
Output is correct |
4 |
Correct |
117 ms |
1048 KB |
Output is correct |
5 |
Correct |
334 ms |
1012 KB |
Output is correct |
6 |
Correct |
365 ms |
852 KB |
Output is correct |
7 |
Correct |
119 ms |
852 KB |
Output is correct |
8 |
Correct |
119 ms |
852 KB |
Output is correct |
9 |
Correct |
123 ms |
944 KB |
Output is correct |
10 |
Correct |
120 ms |
928 KB |
Output is correct |
11 |
Correct |
394 ms |
852 KB |
Output is correct |
12 |
Correct |
405 ms |
1052 KB |
Output is correct |
13 |
Correct |
114 ms |
976 KB |
Output is correct |
14 |
Correct |
122 ms |
1112 KB |
Output is correct |
15 |
Correct |
121 ms |
1108 KB |
Output is correct |
16 |
Correct |
129 ms |
1084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
124 ms |
924 KB |
Output is correct |
12 |
Correct |
116 ms |
936 KB |
Output is correct |
13 |
Correct |
119 ms |
856 KB |
Output is correct |
14 |
Correct |
117 ms |
1048 KB |
Output is correct |
15 |
Correct |
334 ms |
1012 KB |
Output is correct |
16 |
Correct |
365 ms |
852 KB |
Output is correct |
17 |
Correct |
119 ms |
852 KB |
Output is correct |
18 |
Correct |
119 ms |
852 KB |
Output is correct |
19 |
Correct |
123 ms |
944 KB |
Output is correct |
20 |
Correct |
120 ms |
928 KB |
Output is correct |
21 |
Correct |
394 ms |
852 KB |
Output is correct |
22 |
Correct |
405 ms |
1052 KB |
Output is correct |
23 |
Correct |
114 ms |
976 KB |
Output is correct |
24 |
Correct |
122 ms |
1112 KB |
Output is correct |
25 |
Correct |
121 ms |
1108 KB |
Output is correct |
26 |
Correct |
129 ms |
1084 KB |
Output is correct |
27 |
Correct |
114 ms |
1064 KB |
Output is correct |
28 |
Correct |
119 ms |
1052 KB |
Output is correct |
29 |
Correct |
115 ms |
1076 KB |
Output is correct |
30 |
Correct |
118 ms |
1112 KB |
Output is correct |
31 |
Correct |
112 ms |
1008 KB |
Output is correct |
32 |
Correct |
116 ms |
1052 KB |
Output is correct |
33 |
Correct |
413 ms |
1112 KB |
Output is correct |
34 |
Correct |
411 ms |
1052 KB |
Output is correct |
35 |
Correct |
118 ms |
1364 KB |
Output is correct |
36 |
Correct |
117 ms |
1084 KB |
Output is correct |