#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
signed main() {
int n, m;
cin >> n >> m;
vector<array<int, 3> > edges;
for(int i=0; i<m; i++) {
int l, r, k, val;
cin >> l >> r >> k >> val; l++; r++;
if(val == 0) edges.push_back({ l - 1, r, r - l + 1 - k});
else edges.push_back({ r, l - 1, -(r - l + 1) + k - 1 });
}
for(int i=1; i<=n; i++) edges.push_back({ i-1, i, 1 });
for(int i=1; i<=n; i++) edges.push_back({ i, i-1, 0 });
vector<ll> dist(n+1, 1e9); dist[0] = 0;
for(int i=1; i<=n; i++)
for(auto &[u, v, w] : edges) dist[v] = min(dist[v], dist[u] + w);
for(auto &[u, v, w] : edges) {
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 |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 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 |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
796 KB |
Output is correct |
2 |
Correct |
100 ms |
1048 KB |
Output is correct |
3 |
Correct |
102 ms |
1048 KB |
Output is correct |
4 |
Correct |
101 ms |
1052 KB |
Output is correct |
5 |
Correct |
99 ms |
1036 KB |
Output is correct |
6 |
Correct |
99 ms |
900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
796 KB |
Output is correct |
2 |
Correct |
100 ms |
1048 KB |
Output is correct |
3 |
Correct |
102 ms |
1048 KB |
Output is correct |
4 |
Correct |
101 ms |
1052 KB |
Output is correct |
5 |
Correct |
99 ms |
1036 KB |
Output is correct |
6 |
Correct |
99 ms |
900 KB |
Output is correct |
7 |
Correct |
105 ms |
1052 KB |
Output is correct |
8 |
Correct |
108 ms |
1036 KB |
Output is correct |
9 |
Correct |
103 ms |
1052 KB |
Output is correct |
10 |
Correct |
100 ms |
1052 KB |
Output is correct |
11 |
Correct |
101 ms |
1048 KB |
Output is correct |
12 |
Correct |
102 ms |
1052 KB |
Output is correct |
13 |
Correct |
99 ms |
1048 KB |
Output is correct |
14 |
Correct |
105 ms |
1052 KB |
Output is correct |
15 |
Correct |
104 ms |
1048 KB |
Output is correct |
16 |
Correct |
104 ms |
1048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 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 |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
99 ms |
796 KB |
Output is correct |
12 |
Correct |
100 ms |
1048 KB |
Output is correct |
13 |
Correct |
102 ms |
1048 KB |
Output is correct |
14 |
Correct |
101 ms |
1052 KB |
Output is correct |
15 |
Correct |
99 ms |
1036 KB |
Output is correct |
16 |
Correct |
99 ms |
900 KB |
Output is correct |
17 |
Correct |
105 ms |
1052 KB |
Output is correct |
18 |
Correct |
108 ms |
1036 KB |
Output is correct |
19 |
Correct |
103 ms |
1052 KB |
Output is correct |
20 |
Correct |
100 ms |
1052 KB |
Output is correct |
21 |
Correct |
101 ms |
1048 KB |
Output is correct |
22 |
Correct |
102 ms |
1052 KB |
Output is correct |
23 |
Correct |
99 ms |
1048 KB |
Output is correct |
24 |
Correct |
105 ms |
1052 KB |
Output is correct |
25 |
Correct |
104 ms |
1048 KB |
Output is correct |
26 |
Correct |
104 ms |
1048 KB |
Output is correct |
27 |
Correct |
104 ms |
1052 KB |
Output is correct |
28 |
Correct |
102 ms |
1052 KB |
Output is correct |
29 |
Correct |
105 ms |
1048 KB |
Output is correct |
30 |
Correct |
113 ms |
1052 KB |
Output is correct |
31 |
Correct |
98 ms |
1048 KB |
Output is correct |
32 |
Correct |
101 ms |
1048 KB |
Output is correct |
33 |
Correct |
102 ms |
1048 KB |
Output is correct |
34 |
Correct |
102 ms |
1052 KB |
Output is correct |
35 |
Correct |
103 ms |
1052 KB |
Output is correct |
36 |
Correct |
110 ms |
1052 KB |
Output is correct |