#include <bits/stdc++.h>
// author : a1abay
using namespace std;
int n, m, l, r, k, v;
vector<array<int, 3>> e;
vector<int> d(5001, 5001);
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++)
{
e.push_back({i, i + 1, 1});
e.push_back({i + 1, i, 0});
}
while(m--)
{
cin >> l >> r >> k >> v;
if(!v) e.push_back({l, r + 1, r - l + 1 - k});
else e.push_back({r + 1, l, -(r - l + 1 - k + 1)});
}
d[0] = 0;
for(int i = 1; i <= n; i++)
{
for(auto p : e)
{
if(d[p[0]] + p[2] < d[p[1]])
{
d[p[1]] = d[p[0]] + p[2];
if(i == n)
{
cout << -1;
return 0;
}
}
}
}
for(int i = 1; i <= n; i++) cout << d[i] - d[i - 1] << ' ';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 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 |
344 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 |
100 ms |
792 KB |
Output is correct |
2 |
Correct |
99 ms |
820 KB |
Output is correct |
3 |
Correct |
125 ms |
828 KB |
Output is correct |
4 |
Correct |
101 ms |
820 KB |
Output is correct |
5 |
Correct |
242 ms |
792 KB |
Output is correct |
6 |
Correct |
231 ms |
792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
792 KB |
Output is correct |
2 |
Correct |
99 ms |
820 KB |
Output is correct |
3 |
Correct |
125 ms |
828 KB |
Output is correct |
4 |
Correct |
101 ms |
820 KB |
Output is correct |
5 |
Correct |
242 ms |
792 KB |
Output is correct |
6 |
Correct |
231 ms |
792 KB |
Output is correct |
7 |
Correct |
104 ms |
796 KB |
Output is correct |
8 |
Correct |
101 ms |
852 KB |
Output is correct |
9 |
Correct |
107 ms |
844 KB |
Output is correct |
10 |
Correct |
116 ms |
792 KB |
Output is correct |
11 |
Correct |
310 ms |
792 KB |
Output is correct |
12 |
Correct |
329 ms |
796 KB |
Output is correct |
13 |
Correct |
97 ms |
816 KB |
Output is correct |
14 |
Correct |
104 ms |
852 KB |
Output is correct |
15 |
Correct |
105 ms |
792 KB |
Output is correct |
16 |
Correct |
110 ms |
796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
100 ms |
792 KB |
Output is correct |
12 |
Correct |
99 ms |
820 KB |
Output is correct |
13 |
Correct |
125 ms |
828 KB |
Output is correct |
14 |
Correct |
101 ms |
820 KB |
Output is correct |
15 |
Correct |
242 ms |
792 KB |
Output is correct |
16 |
Correct |
231 ms |
792 KB |
Output is correct |
17 |
Correct |
104 ms |
796 KB |
Output is correct |
18 |
Correct |
101 ms |
852 KB |
Output is correct |
19 |
Correct |
107 ms |
844 KB |
Output is correct |
20 |
Correct |
116 ms |
792 KB |
Output is correct |
21 |
Correct |
310 ms |
792 KB |
Output is correct |
22 |
Correct |
329 ms |
796 KB |
Output is correct |
23 |
Correct |
97 ms |
816 KB |
Output is correct |
24 |
Correct |
104 ms |
852 KB |
Output is correct |
25 |
Correct |
105 ms |
792 KB |
Output is correct |
26 |
Correct |
110 ms |
796 KB |
Output is correct |
27 |
Correct |
96 ms |
792 KB |
Output is correct |
28 |
Correct |
100 ms |
792 KB |
Output is correct |
29 |
Correct |
99 ms |
796 KB |
Output is correct |
30 |
Correct |
100 ms |
792 KB |
Output is correct |
31 |
Correct |
96 ms |
816 KB |
Output is correct |
32 |
Correct |
98 ms |
820 KB |
Output is correct |
33 |
Correct |
248 ms |
1048 KB |
Output is correct |
34 |
Correct |
298 ms |
796 KB |
Output is correct |
35 |
Correct |
100 ms |
792 KB |
Output is correct |
36 |
Correct |
113 ms |
824 KB |
Output is correct |