#include <bits/stdc++.h>
using namespace std;
#define ll int
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll,ll>
int main() {
ll n, m;
cin >> n >> m;
vector<pair<pair<ll, ll>, ll>> graph(n+1);
for (ll i = 0; i < n; i++) graph.push_back({{i, i+1}, 1}), graph.push_back({{i+1, i}, 0});
for (ll i = 0; i < m; i++) {
ll l, r, k, v;
cin >> l >> r >> k >> v;
k--;
if (v == 1) {
// cout << l << ' ' << r+1 << ' ' << -((r-l+1)-k) << endl;
graph.push_back({{r+1, l}, k-(r-l+1)});
} else {
// cout << r+1 << ' ' << l << ' ' << (r-l+1)-k-1 << endl;
graph.push_back({{l, r+1}, (r-l+1)-k-1});
}
}
vll dist(n+1, 1e9);
dist[0] = 0;
bool changed = true;
for (ll i = 0; i < n+2; i++) {
// for (ll j = 0; j < n+1; j++) cout << dist[j] << ' ';
// cout << endl;
changed = false;
for (auto e : graph) {
if (dist[e.first.second] > dist[e.first.first] + e.second) {
changed = true;
dist[e.first.second] = dist[e.first.first] + e.second;
}
}
if (!changed) break;
}
if (changed) {
cout << -1 << endl;
return 0;
}
for (ll i = 0; i < n; i++) cout << dist[i+1] - dist[i] << ' ';
cout << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
932 KB |
Output is correct |
2 |
Correct |
13 ms |
1028 KB |
Output is correct |
3 |
Correct |
12 ms |
996 KB |
Output is correct |
4 |
Correct |
12 ms |
936 KB |
Output is correct |
5 |
Correct |
396 ms |
908 KB |
Output is correct |
6 |
Correct |
348 ms |
932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
932 KB |
Output is correct |
2 |
Correct |
13 ms |
1028 KB |
Output is correct |
3 |
Correct |
12 ms |
996 KB |
Output is correct |
4 |
Correct |
12 ms |
936 KB |
Output is correct |
5 |
Correct |
396 ms |
908 KB |
Output is correct |
6 |
Correct |
348 ms |
932 KB |
Output is correct |
7 |
Correct |
13 ms |
936 KB |
Output is correct |
8 |
Correct |
14 ms |
948 KB |
Output is correct |
9 |
Correct |
18 ms |
944 KB |
Output is correct |
10 |
Correct |
12 ms |
1044 KB |
Output is correct |
11 |
Correct |
453 ms |
948 KB |
Output is correct |
12 |
Correct |
444 ms |
996 KB |
Output is correct |
13 |
Correct |
12 ms |
1044 KB |
Output is correct |
14 |
Correct |
11 ms |
932 KB |
Output is correct |
15 |
Correct |
19 ms |
948 KB |
Output is correct |
16 |
Correct |
64 ms |
1044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
11 ms |
932 KB |
Output is correct |
12 |
Correct |
13 ms |
1028 KB |
Output is correct |
13 |
Correct |
12 ms |
996 KB |
Output is correct |
14 |
Correct |
12 ms |
936 KB |
Output is correct |
15 |
Correct |
396 ms |
908 KB |
Output is correct |
16 |
Correct |
348 ms |
932 KB |
Output is correct |
17 |
Correct |
13 ms |
936 KB |
Output is correct |
18 |
Correct |
14 ms |
948 KB |
Output is correct |
19 |
Correct |
18 ms |
944 KB |
Output is correct |
20 |
Correct |
12 ms |
1044 KB |
Output is correct |
21 |
Correct |
453 ms |
948 KB |
Output is correct |
22 |
Correct |
444 ms |
996 KB |
Output is correct |
23 |
Correct |
12 ms |
1044 KB |
Output is correct |
24 |
Correct |
11 ms |
932 KB |
Output is correct |
25 |
Correct |
19 ms |
948 KB |
Output is correct |
26 |
Correct |
64 ms |
1044 KB |
Output is correct |
27 |
Correct |
12 ms |
948 KB |
Output is correct |
28 |
Correct |
13 ms |
944 KB |
Output is correct |
29 |
Correct |
15 ms |
1040 KB |
Output is correct |
30 |
Correct |
14 ms |
1004 KB |
Output is correct |
31 |
Correct |
11 ms |
920 KB |
Output is correct |
32 |
Correct |
13 ms |
1032 KB |
Output is correct |
33 |
Correct |
418 ms |
1032 KB |
Output is correct |
34 |
Correct |
406 ms |
936 KB |
Output is correct |
35 |
Correct |
12 ms |
984 KB |
Output is correct |
36 |
Correct |
14 ms |
932 KB |
Output is correct |