#include <climits>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define int ll
struct edge {
int from, to, w;
};
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<edge> edges;
for (int i = 0; i < n; i++) {
edges.push_back({ i, i + 1, 1 });
edges.push_back({ i + 1, i, 0 });
}
for (int i = 0; i < m; i++) {
int l, r, k, v;
cin >> l >> r >> k >> v;
if (v == 0) {
// p[r + 1] - p[l] <= r - l + 1 - k
// p[r + 1] <= p[l] + r - l + 1 - k
edges.push_back({ l, r + 1, r - l + 1 - k });
}
else {
// p[r + 1] - p[l] >= (r - l + 1) - (k - 1)
// p[r + 1] - r + l - 1 + k - 1 >= p[l]
// p[l] <= p[r + 1] + (-r + l + k - 2)
edges.push_back({ r + 1, l, -r + l + k - 2 });
}
}
vector<int> dist(n + 1, INT_MAX / 3);
dist[0] = 0;
bool solution_found;
for (int i = 0; i < n + 1; i++) {
solution_found = true;
for (edge const& e : edges) {
int const new_dist = dist[e.from] + e.w;
if (new_dist < dist[e.to]) {
dist[e.to] = new_dist;
solution_found = false;
}
}
if (solution_found)
break;
}
if (!solution_found) {
cout << "-1\n";
return 0;
}
for (int i = 0; i < n; i++)
cout << dist[i + 1] - dist[i] << " ";
cout << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
356 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
408 KB |
Output is correct |
4 |
Correct |
2 ms |
352 KB |
Output is correct |
5 |
Correct |
2 ms |
352 KB |
Output is correct |
6 |
Correct |
2 ms |
352 KB |
Output is correct |
7 |
Correct |
1 ms |
608 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
2 ms |
352 KB |
Output is correct |
10 |
Correct |
1 ms |
352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1368 KB |
Output is correct |
2 |
Correct |
7 ms |
1368 KB |
Output is correct |
3 |
Correct |
7 ms |
1368 KB |
Output is correct |
4 |
Correct |
6 ms |
1368 KB |
Output is correct |
5 |
Correct |
142 ms |
1372 KB |
Output is correct |
6 |
Correct |
135 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1368 KB |
Output is correct |
2 |
Correct |
7 ms |
1368 KB |
Output is correct |
3 |
Correct |
7 ms |
1368 KB |
Output is correct |
4 |
Correct |
6 ms |
1368 KB |
Output is correct |
5 |
Correct |
142 ms |
1372 KB |
Output is correct |
6 |
Correct |
135 ms |
1372 KB |
Output is correct |
7 |
Correct |
9 ms |
1372 KB |
Output is correct |
8 |
Correct |
6 ms |
1372 KB |
Output is correct |
9 |
Correct |
6 ms |
1360 KB |
Output is correct |
10 |
Correct |
6 ms |
1360 KB |
Output is correct |
11 |
Correct |
133 ms |
1360 KB |
Output is correct |
12 |
Correct |
135 ms |
1496 KB |
Output is correct |
13 |
Correct |
7 ms |
1472 KB |
Output is correct |
14 |
Correct |
7 ms |
1360 KB |
Output is correct |
15 |
Correct |
7 ms |
1360 KB |
Output is correct |
16 |
Correct |
40 ms |
1360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
356 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
408 KB |
Output is correct |
4 |
Correct |
2 ms |
352 KB |
Output is correct |
5 |
Correct |
2 ms |
352 KB |
Output is correct |
6 |
Correct |
2 ms |
352 KB |
Output is correct |
7 |
Correct |
1 ms |
608 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
2 ms |
352 KB |
Output is correct |
10 |
Correct |
1 ms |
352 KB |
Output is correct |
11 |
Correct |
6 ms |
1368 KB |
Output is correct |
12 |
Correct |
7 ms |
1368 KB |
Output is correct |
13 |
Correct |
7 ms |
1368 KB |
Output is correct |
14 |
Correct |
6 ms |
1368 KB |
Output is correct |
15 |
Correct |
142 ms |
1372 KB |
Output is correct |
16 |
Correct |
135 ms |
1372 KB |
Output is correct |
17 |
Correct |
9 ms |
1372 KB |
Output is correct |
18 |
Correct |
6 ms |
1372 KB |
Output is correct |
19 |
Correct |
6 ms |
1360 KB |
Output is correct |
20 |
Correct |
6 ms |
1360 KB |
Output is correct |
21 |
Correct |
133 ms |
1360 KB |
Output is correct |
22 |
Correct |
135 ms |
1496 KB |
Output is correct |
23 |
Correct |
7 ms |
1472 KB |
Output is correct |
24 |
Correct |
7 ms |
1360 KB |
Output is correct |
25 |
Correct |
7 ms |
1360 KB |
Output is correct |
26 |
Correct |
40 ms |
1360 KB |
Output is correct |
27 |
Correct |
5 ms |
1360 KB |
Output is correct |
28 |
Correct |
6 ms |
1360 KB |
Output is correct |
29 |
Correct |
10 ms |
1360 KB |
Output is correct |
30 |
Correct |
7 ms |
1360 KB |
Output is correct |
31 |
Correct |
5 ms |
1360 KB |
Output is correct |
32 |
Correct |
6 ms |
1472 KB |
Output is correct |
33 |
Correct |
161 ms |
1360 KB |
Output is correct |
34 |
Correct |
134 ms |
1360 KB |
Output is correct |
35 |
Correct |
6 ms |
1360 KB |
Output is correct |
36 |
Correct |
8 ms |
1360 KB |
Output is correct |