#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<pair<int, int>>> g(n + 1);
while (m--) {
int l, r, k, x;
cin >> l >> r >> k >> x;
++r;
if (x == 0) g[l].emplace_back(r - l - k, r);
else g[r].emplace_back(k - 1 - r + l, l);
}
for (int i = 0; i < n; ++i) g[i].emplace_back(1, i + 1);
for (int i = 0; i < n; ++i) g[i + 1].emplace_back(0, i);
vector<int> min_dist(n + 1, n + 2);
min_dist[0] = 0;
bool unfinished = true;
for (int i = 0; unfinished; ++i) {
if (i > n + 1) break;
unfinished = false;
for (int u = 0; u <= n; ++u) {
for (auto p : g[u]) {
if (min_dist[u] + p.first < min_dist[p.second]) {
min_dist[p.second] = min_dist[u] + p.first;
unfinished = true;
}
}
}
}
if (unfinished) {
cout << -1 << endl;
} else {
for (int i = 0; i < n; ++i) {
cout << min_dist[i + 1] - min_dist[i] << ' ';
}
cout << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
716 KB |
Output is correct |
2 |
Correct |
6 ms |
716 KB |
Output is correct |
3 |
Correct |
6 ms |
716 KB |
Output is correct |
4 |
Correct |
6 ms |
716 KB |
Output is correct |
5 |
Execution timed out |
607 ms |
876 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
716 KB |
Output is correct |
2 |
Correct |
6 ms |
716 KB |
Output is correct |
3 |
Correct |
6 ms |
716 KB |
Output is correct |
4 |
Correct |
6 ms |
716 KB |
Output is correct |
5 |
Execution timed out |
607 ms |
876 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
5 ms |
716 KB |
Output is correct |
12 |
Correct |
6 ms |
716 KB |
Output is correct |
13 |
Correct |
6 ms |
716 KB |
Output is correct |
14 |
Correct |
6 ms |
716 KB |
Output is correct |
15 |
Execution timed out |
607 ms |
876 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |