/**
* author: NimaAryan
* created: 2024-08-11 17:08:02
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#endif
using i64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<array<int, 3>> e(m);
for (int i = 0; i < m; ++i) {
int l, r, k, value;
cin >> l >> r >> k >> value;
++r;
if (value == 1) {
e[i] = {l, r, k - 1};
} else {
e[i] = {r, l, -k};
}
}
for (int i = 0; i + 1 <= n; ++i) {
e.push_back({i, i + 1, 1});
e.push_back({i + 1, i, 0});
}
constexpr int inf = 1E9;
vector<int> s(n + 1, inf);
s[0] = 0;
int last = -1;
for (int it = 0; it < n; ++it) {
for (auto [i, j, w] : e) {
if (s[i] + w < s[j]) {
s[j] = s[i] + w;
last = it;
}
}
if (last != it) {
break;
}
}
if (last + 1 == n) {
cout << -1 << "\n";
return 0;
}
for (int i = 0; i < n; ++i) {
cout << !(s[i + 1] - s[i]) << " \n"[i + 1 == n];
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 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 |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
904 KB |
Output is correct |
2 |
Correct |
2 ms |
936 KB |
Output is correct |
3 |
Correct |
2 ms |
1116 KB |
Output is correct |
4 |
Correct |
5 ms |
936 KB |
Output is correct |
5 |
Correct |
365 ms |
1116 KB |
Output is correct |
6 |
Correct |
317 ms |
1112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
904 KB |
Output is correct |
2 |
Correct |
2 ms |
936 KB |
Output is correct |
3 |
Correct |
2 ms |
1116 KB |
Output is correct |
4 |
Correct |
5 ms |
936 KB |
Output is correct |
5 |
Correct |
365 ms |
1116 KB |
Output is correct |
6 |
Correct |
317 ms |
1112 KB |
Output is correct |
7 |
Correct |
3 ms |
856 KB |
Output is correct |
8 |
Correct |
3 ms |
860 KB |
Output is correct |
9 |
Correct |
3 ms |
1116 KB |
Output is correct |
10 |
Correct |
3 ms |
1116 KB |
Output is correct |
11 |
Correct |
94 ms |
1116 KB |
Output is correct |
12 |
Correct |
97 ms |
1116 KB |
Output is correct |
13 |
Correct |
3 ms |
1116 KB |
Output is correct |
14 |
Correct |
15 ms |
968 KB |
Output is correct |
15 |
Correct |
19 ms |
856 KB |
Output is correct |
16 |
Correct |
9 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
456 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 |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
904 KB |
Output is correct |
12 |
Correct |
2 ms |
936 KB |
Output is correct |
13 |
Correct |
2 ms |
1116 KB |
Output is correct |
14 |
Correct |
5 ms |
936 KB |
Output is correct |
15 |
Correct |
365 ms |
1116 KB |
Output is correct |
16 |
Correct |
317 ms |
1112 KB |
Output is correct |
17 |
Correct |
3 ms |
856 KB |
Output is correct |
18 |
Correct |
3 ms |
860 KB |
Output is correct |
19 |
Correct |
3 ms |
1116 KB |
Output is correct |
20 |
Correct |
3 ms |
1116 KB |
Output is correct |
21 |
Correct |
94 ms |
1116 KB |
Output is correct |
22 |
Correct |
97 ms |
1116 KB |
Output is correct |
23 |
Correct |
3 ms |
1116 KB |
Output is correct |
24 |
Correct |
15 ms |
968 KB |
Output is correct |
25 |
Correct |
19 ms |
856 KB |
Output is correct |
26 |
Correct |
9 ms |
860 KB |
Output is correct |
27 |
Correct |
3 ms |
968 KB |
Output is correct |
28 |
Correct |
3 ms |
1168 KB |
Output is correct |
29 |
Correct |
3 ms |
1116 KB |
Output is correct |
30 |
Correct |
3 ms |
1112 KB |
Output is correct |
31 |
Correct |
3 ms |
1112 KB |
Output is correct |
32 |
Correct |
4 ms |
1116 KB |
Output is correct |
33 |
Correct |
176 ms |
980 KB |
Output is correct |
34 |
Correct |
178 ms |
1116 KB |
Output is correct |
35 |
Correct |
3 ms |
1116 KB |
Output is correct |
36 |
Correct |
4 ms |
1116 KB |
Output is correct |