#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define sz size
const int inf = 1e8;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin >> n >> m;
n++;
vector<pii> adj[n];
for (int i =0; i < n-1; i++) adj[i].pb((pii) {i+1,1});
for (int i = 1; i < n; i++) adj[i].pb((pii) {i-1,0});
int l,r,k,v;
for (int i = 0; i < m; i++){
cin >> l >> r >> k >> v;
r++;
if (v == 0) adj[r].pb((pii) {l,-k});
else adj[l].pb((pii) {r,k-1});
}
int d[n];
for (int i =0; i < n; i++) d[i] = inf;
d[0] = 0;
for (int i =0; i < n-1; i++){
for (int j =0; j < n; j++){
for (pii c : adj[j]) d[c.f] = min(d[c.f], d[j]+c.s);
}
}
bool f = false;
for (int i = 0; i < n; i++){
for (pii c : adj[i]) if (d[c.f] > d[i]+c.s){ f = true; break;}
}
if (f){ cout << "-1\n"; return 0;}
for (int i = 1; i < n; i++){
if (d[i] > d[i-1]) cout << "0 ";
else cout << "1 ";
}
cout << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 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 |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
1032 KB |
Output is correct |
2 |
Correct |
146 ms |
856 KB |
Output is correct |
3 |
Correct |
160 ms |
860 KB |
Output is correct |
4 |
Correct |
156 ms |
1044 KB |
Output is correct |
5 |
Correct |
157 ms |
888 KB |
Output is correct |
6 |
Correct |
147 ms |
1048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
1032 KB |
Output is correct |
2 |
Correct |
146 ms |
856 KB |
Output is correct |
3 |
Correct |
160 ms |
860 KB |
Output is correct |
4 |
Correct |
156 ms |
1044 KB |
Output is correct |
5 |
Correct |
157 ms |
888 KB |
Output is correct |
6 |
Correct |
147 ms |
1048 KB |
Output is correct |
7 |
Correct |
175 ms |
1064 KB |
Output is correct |
8 |
Correct |
173 ms |
856 KB |
Output is correct |
9 |
Correct |
211 ms |
860 KB |
Output is correct |
10 |
Correct |
171 ms |
1080 KB |
Output is correct |
11 |
Correct |
149 ms |
856 KB |
Output is correct |
12 |
Correct |
151 ms |
856 KB |
Output is correct |
13 |
Correct |
164 ms |
860 KB |
Output is correct |
14 |
Correct |
167 ms |
1072 KB |
Output is correct |
15 |
Correct |
178 ms |
856 KB |
Output is correct |
16 |
Correct |
170 ms |
1068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 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 |
344 KB |
Output is correct |
11 |
Correct |
159 ms |
1032 KB |
Output is correct |
12 |
Correct |
146 ms |
856 KB |
Output is correct |
13 |
Correct |
160 ms |
860 KB |
Output is correct |
14 |
Correct |
156 ms |
1044 KB |
Output is correct |
15 |
Correct |
157 ms |
888 KB |
Output is correct |
16 |
Correct |
147 ms |
1048 KB |
Output is correct |
17 |
Correct |
175 ms |
1064 KB |
Output is correct |
18 |
Correct |
173 ms |
856 KB |
Output is correct |
19 |
Correct |
211 ms |
860 KB |
Output is correct |
20 |
Correct |
171 ms |
1080 KB |
Output is correct |
21 |
Correct |
149 ms |
856 KB |
Output is correct |
22 |
Correct |
151 ms |
856 KB |
Output is correct |
23 |
Correct |
164 ms |
860 KB |
Output is correct |
24 |
Correct |
167 ms |
1072 KB |
Output is correct |
25 |
Correct |
178 ms |
856 KB |
Output is correct |
26 |
Correct |
170 ms |
1068 KB |
Output is correct |
27 |
Correct |
163 ms |
860 KB |
Output is correct |
28 |
Correct |
207 ms |
1084 KB |
Output is correct |
29 |
Correct |
190 ms |
856 KB |
Output is correct |
30 |
Correct |
176 ms |
1076 KB |
Output is correct |
31 |
Correct |
162 ms |
860 KB |
Output is correct |
32 |
Correct |
177 ms |
856 KB |
Output is correct |
33 |
Correct |
189 ms |
1088 KB |
Output is correct |
34 |
Correct |
182 ms |
856 KB |
Output is correct |
35 |
Correct |
192 ms |
1076 KB |
Output is correct |
36 |
Correct |
159 ms |
1068 KB |
Output is correct |