#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] >= k - 1
// p[r + 1] + 1 - k >= p[l]
// p[l] <= p[r + 1] + 1 - k
edges.push_back({ r + 1, l, 1 - k });
}
}
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";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1364 KB |
Output is correct |
2 |
Correct |
8 ms |
1480 KB |
Output is correct |
3 |
Correct |
7 ms |
1360 KB |
Output is correct |
4 |
Incorrect |
7 ms |
1360 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1364 KB |
Output is correct |
2 |
Correct |
8 ms |
1480 KB |
Output is correct |
3 |
Correct |
7 ms |
1360 KB |
Output is correct |
4 |
Incorrect |
7 ms |
1360 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |