#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define endl '\n'
#define mod 1000000007
//\
#define mod 1686876991
const int maxn = 1000001;
const int INF = 1e8;
int dist[maxn];
vector<array<int, 3>> E;
signed main () {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
for (int i = 0 ; i < m ; i++) {
int x, y, k, v;
cin >> x >> y >> k >> v;
x++,y++;
int s = y - x + 1;
if (v == 1) {
k--;
E.push_back({y, x - 1, k - s});
//cerr << y << " " << x - 1 << " " << k - s << endl;
} else {
E.push_back({x - 1, y, s - k});
//cerr << x - 1 << " " << y << " " << s - k << endl;
}
}
for (int i = 1 ; i <= n ; i++) dist[i] = INF;
for (int i = 0 ; i < n ; i++) {
E.push_back({i, i + 1, 1});
E.push_back({i + 1, i, 0});
//cerr << i << " " << i + 1 << " " << 1 << endl;
//cerr << i + 1 << " " << i << " " << 0 << endl;
}
for (int iter = 0 ; iter < n ; iter++) {
// for (int i = 0 ; i <= n ; i++) {
// cerr << dist[i] << " ";
// }
// cerr << endl;
for (auto [u,v,w] : E) {
if (dist[u] != INF)
dist[v] = min(dist[v], dist[u] + w);
}
}
bool imp = 0;
for (auto [u,v,w] : E) {
if (dist[v] != INF && dist[u] != INF && dist[v] > dist[u] + w) imp = 1;
}
// for (int i = 0 ; i <= n ; i++) {
// cerr << dist[i] << " ";
// }
if (imp) cout << -1;
else {
for (int i = 1 ; i <= n ; i++) {
cout << (dist[i] > dist[i-1]) << " ";
}
}
}
Compilation message
restore.cpp:17:1: warning: multi-line comment [-Wcomment]
17 | //\
| ^
restore.cpp: In function 'int main()':
restore.cpp:63:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
63 | for (auto [u,v,w] : E) {
| ^
restore.cpp:71:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
71 | for (auto [u,v,w] : E) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
316 ms |
1364 KB |
Output is correct |
2 |
Correct |
325 ms |
1360 KB |
Output is correct |
3 |
Correct |
317 ms |
1360 KB |
Output is correct |
4 |
Correct |
297 ms |
1380 KB |
Output is correct |
5 |
Correct |
314 ms |
1360 KB |
Output is correct |
6 |
Correct |
301 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
316 ms |
1364 KB |
Output is correct |
2 |
Correct |
325 ms |
1360 KB |
Output is correct |
3 |
Correct |
317 ms |
1360 KB |
Output is correct |
4 |
Correct |
297 ms |
1380 KB |
Output is correct |
5 |
Correct |
314 ms |
1360 KB |
Output is correct |
6 |
Correct |
301 ms |
1364 KB |
Output is correct |
7 |
Correct |
311 ms |
1360 KB |
Output is correct |
8 |
Correct |
319 ms |
1360 KB |
Output is correct |
9 |
Correct |
294 ms |
1360 KB |
Output is correct |
10 |
Correct |
295 ms |
1360 KB |
Output is correct |
11 |
Correct |
307 ms |
1360 KB |
Output is correct |
12 |
Correct |
296 ms |
1360 KB |
Output is correct |
13 |
Correct |
297 ms |
1360 KB |
Output is correct |
14 |
Correct |
308 ms |
1352 KB |
Output is correct |
15 |
Correct |
302 ms |
1364 KB |
Output is correct |
16 |
Correct |
303 ms |
1376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
236 KB |
Output is correct |
11 |
Correct |
316 ms |
1364 KB |
Output is correct |
12 |
Correct |
325 ms |
1360 KB |
Output is correct |
13 |
Correct |
317 ms |
1360 KB |
Output is correct |
14 |
Correct |
297 ms |
1380 KB |
Output is correct |
15 |
Correct |
314 ms |
1360 KB |
Output is correct |
16 |
Correct |
301 ms |
1364 KB |
Output is correct |
17 |
Correct |
311 ms |
1360 KB |
Output is correct |
18 |
Correct |
319 ms |
1360 KB |
Output is correct |
19 |
Correct |
294 ms |
1360 KB |
Output is correct |
20 |
Correct |
295 ms |
1360 KB |
Output is correct |
21 |
Correct |
307 ms |
1360 KB |
Output is correct |
22 |
Correct |
296 ms |
1360 KB |
Output is correct |
23 |
Correct |
297 ms |
1360 KB |
Output is correct |
24 |
Correct |
308 ms |
1352 KB |
Output is correct |
25 |
Correct |
302 ms |
1364 KB |
Output is correct |
26 |
Correct |
303 ms |
1376 KB |
Output is correct |
27 |
Correct |
295 ms |
1360 KB |
Output is correct |
28 |
Correct |
299 ms |
1360 KB |
Output is correct |
29 |
Correct |
313 ms |
1360 KB |
Output is correct |
30 |
Correct |
298 ms |
1360 KB |
Output is correct |
31 |
Correct |
286 ms |
1360 KB |
Output is correct |
32 |
Correct |
308 ms |
1360 KB |
Output is correct |
33 |
Correct |
308 ms |
1360 KB |
Output is correct |
34 |
Correct |
303 ms |
1372 KB |
Output is correct |
35 |
Correct |
297 ms |
1360 KB |
Output is correct |
36 |
Correct |
312 ms |
1340 KB |
Output is correct |