#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> dist(n+1, 1e9); dist[0] = 0;
for(int i=1; i<=n; i++)
for(auto &[u, v, w] : E) dist[v] = min(dist[v], dist[u] + w);
for(auto &[u, v, w] : E) {
if(dist[v] > dist[u] + w) {
cout << -1 << '\n';
return 0;
}
}
for(int i=1; i<=n; i++) cout << (dist[i] > dist[i-1]) << " ";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
87 ms |
652 KB |
Output is correct |
2 |
Correct |
85 ms |
604 KB |
Output is correct |
3 |
Correct |
84 ms |
604 KB |
Output is correct |
4 |
Correct |
85 ms |
664 KB |
Output is correct |
5 |
Correct |
85 ms |
648 KB |
Output is correct |
6 |
Correct |
82 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
652 KB |
Output is correct |
2 |
Correct |
85 ms |
604 KB |
Output is correct |
3 |
Correct |
84 ms |
604 KB |
Output is correct |
4 |
Correct |
85 ms |
664 KB |
Output is correct |
5 |
Correct |
85 ms |
648 KB |
Output is correct |
6 |
Correct |
82 ms |
600 KB |
Output is correct |
7 |
Correct |
85 ms |
600 KB |
Output is correct |
8 |
Correct |
86 ms |
656 KB |
Output is correct |
9 |
Correct |
87 ms |
672 KB |
Output is correct |
10 |
Correct |
87 ms |
604 KB |
Output is correct |
11 |
Correct |
85 ms |
656 KB |
Output is correct |
12 |
Correct |
86 ms |
600 KB |
Output is correct |
13 |
Correct |
83 ms |
600 KB |
Output is correct |
14 |
Correct |
107 ms |
600 KB |
Output is correct |
15 |
Correct |
87 ms |
660 KB |
Output is correct |
16 |
Correct |
92 ms |
676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
87 ms |
652 KB |
Output is correct |
12 |
Correct |
85 ms |
604 KB |
Output is correct |
13 |
Correct |
84 ms |
604 KB |
Output is correct |
14 |
Correct |
85 ms |
664 KB |
Output is correct |
15 |
Correct |
85 ms |
648 KB |
Output is correct |
16 |
Correct |
82 ms |
600 KB |
Output is correct |
17 |
Correct |
85 ms |
600 KB |
Output is correct |
18 |
Correct |
86 ms |
656 KB |
Output is correct |
19 |
Correct |
87 ms |
672 KB |
Output is correct |
20 |
Correct |
87 ms |
604 KB |
Output is correct |
21 |
Correct |
85 ms |
656 KB |
Output is correct |
22 |
Correct |
86 ms |
600 KB |
Output is correct |
23 |
Correct |
83 ms |
600 KB |
Output is correct |
24 |
Correct |
107 ms |
600 KB |
Output is correct |
25 |
Correct |
87 ms |
660 KB |
Output is correct |
26 |
Correct |
92 ms |
676 KB |
Output is correct |
27 |
Correct |
83 ms |
604 KB |
Output is correct |
28 |
Correct |
86 ms |
660 KB |
Output is correct |
29 |
Correct |
89 ms |
648 KB |
Output is correct |
30 |
Correct |
101 ms |
604 KB |
Output is correct |
31 |
Correct |
90 ms |
648 KB |
Output is correct |
32 |
Correct |
84 ms |
604 KB |
Output is correct |
33 |
Correct |
87 ms |
656 KB |
Output is correct |
34 |
Correct |
84 ms |
652 KB |
Output is correct |
35 |
Correct |
87 ms |
604 KB |
Output is correct |
36 |
Correct |
89 ms |
648 KB |
Output is correct |