#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
array<int, 3> E[m+2*n];
for(int i=0; i<m; i++) {
int l, r, k, val;
cin >> l >> r >> k >> val; l++; r++;
if(!val) E[i] = { l - 1, r, r - l + 1 - k };
else E[i] = { r, l - 1, -(r - l + 1) + k - 1 };
}
for(int i=1; i<=n; i++) E[m+i-1] = { i-1, i, 1 };
for(int i=1; i<=n; i++) E[m+n+i-1] = { i, i-1, 0 };
vector<int> D(n+1, 1e9); D[0] = 0;
for(int i=1; i<=n; i++)
for(auto &[u, v, w] : E) D[v] = min(D[v], D[u] + w);
for(auto &[u, v, w] : E) {
if(D[v] > D[u] + w) {
cout << -1 << '\n';
return 0;
}
}
for(int i=1; i<=n; i++) cout << (D[i] > D[i-1]) << " ";
return 0;
}
# |
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 |
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 |
88 ms |
648 KB |
Output is correct |
2 |
Correct |
85 ms |
600 KB |
Output is correct |
3 |
Correct |
87 ms |
664 KB |
Output is correct |
4 |
Correct |
84 ms |
600 KB |
Output is correct |
5 |
Correct |
88 ms |
856 KB |
Output is correct |
6 |
Correct |
83 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
648 KB |
Output is correct |
2 |
Correct |
85 ms |
600 KB |
Output is correct |
3 |
Correct |
87 ms |
664 KB |
Output is correct |
4 |
Correct |
84 ms |
600 KB |
Output is correct |
5 |
Correct |
88 ms |
856 KB |
Output is correct |
6 |
Correct |
83 ms |
600 KB |
Output is correct |
7 |
Correct |
86 ms |
604 KB |
Output is correct |
8 |
Correct |
86 ms |
668 KB |
Output is correct |
9 |
Correct |
87 ms |
656 KB |
Output is correct |
10 |
Correct |
89 ms |
604 KB |
Output is correct |
11 |
Correct |
85 ms |
604 KB |
Output is correct |
12 |
Correct |
85 ms |
604 KB |
Output is correct |
13 |
Correct |
83 ms |
600 KB |
Output is correct |
14 |
Correct |
91 ms |
600 KB |
Output is correct |
15 |
Correct |
87 ms |
668 KB |
Output is correct |
16 |
Correct |
100 ms |
604 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 |
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 |
88 ms |
648 KB |
Output is correct |
12 |
Correct |
85 ms |
600 KB |
Output is correct |
13 |
Correct |
87 ms |
664 KB |
Output is correct |
14 |
Correct |
84 ms |
600 KB |
Output is correct |
15 |
Correct |
88 ms |
856 KB |
Output is correct |
16 |
Correct |
83 ms |
600 KB |
Output is correct |
17 |
Correct |
86 ms |
604 KB |
Output is correct |
18 |
Correct |
86 ms |
668 KB |
Output is correct |
19 |
Correct |
87 ms |
656 KB |
Output is correct |
20 |
Correct |
89 ms |
604 KB |
Output is correct |
21 |
Correct |
85 ms |
604 KB |
Output is correct |
22 |
Correct |
85 ms |
604 KB |
Output is correct |
23 |
Correct |
83 ms |
600 KB |
Output is correct |
24 |
Correct |
91 ms |
600 KB |
Output is correct |
25 |
Correct |
87 ms |
668 KB |
Output is correct |
26 |
Correct |
100 ms |
604 KB |
Output is correct |
27 |
Correct |
83 ms |
604 KB |
Output is correct |
28 |
Correct |
86 ms |
652 KB |
Output is correct |
29 |
Correct |
97 ms |
604 KB |
Output is correct |
30 |
Correct |
92 ms |
604 KB |
Output is correct |
31 |
Correct |
83 ms |
644 KB |
Output is correct |
32 |
Correct |
87 ms |
604 KB |
Output is correct |
33 |
Correct |
94 ms |
656 KB |
Output is correct |
34 |
Correct |
84 ms |
600 KB |
Output is correct |
35 |
Correct |
86 ms |
656 KB |
Output is correct |
36 |
Correct |
86 ms |
600 KB |
Output is correct |