#include<bits/stdc++.h>
using namespace std;
const int maxn=5000+10;
vector<pair<int,int>>adj[maxn];
int f=0,n,m,dis[maxn];
/*
if w==0{
ps[r]<=ps[l]+(len-k)
}else{
ps[r]-(len-k+1)>=ps[l]
}
*/
void vorod(){
cin>>n>>m;
for(int i=1;i<=n;i++){
adj[i-1].push_back(make_pair(1,i));
adj[i].push_back(make_pair(0,i-1));
}
for(int i=0;i<m;i++){
int l,r,k,w;
cin>>l>>r>>k>>w;
r++;
int len=r-l;
if(w==0){
adj[l].push_back(make_pair(len-k,r));
}else{
adj[r].push_back(make_pair(-(len-k+1),l));
}
}
}
void caldis(){
dis[0]=0;
for(int i=1;i<=n;i++){
dis[i]=n*10;
}
for(int ted=0;ted<=n;ted++){
for(int i=0;i<=n;i++){
for(auto x:adj[i]){
dis[x.second]=min(dis[x.second],dis[i]+x.first);
}
}
}
for(int i=0;i<=n;i++){
for(auto x:adj[i]){
if(dis[x.second]>dis[i]+x.first){
f=1;
break;
}
}
}
}
void khor(){
if(f){
cout<<-1<<"\n";
return ;
}
for(int i=1;i<=n;i++){
if(dis[i]==dis[i-1]){
cout<<0<<" ";
}else{
cout<<1<<" ";
}
}
cout<<"\n";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
vorod();
caldis();
khor();
}
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
170 ms |
900 KB |
Output is correct |
2 |
Correct |
174 ms |
1104 KB |
Output is correct |
3 |
Correct |
166 ms |
856 KB |
Output is correct |
4 |
Correct |
159 ms |
860 KB |
Output is correct |
5 |
Correct |
176 ms |
1060 KB |
Output is correct |
6 |
Correct |
222 ms |
1044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
170 ms |
900 KB |
Output is correct |
2 |
Correct |
174 ms |
1104 KB |
Output is correct |
3 |
Correct |
166 ms |
856 KB |
Output is correct |
4 |
Correct |
159 ms |
860 KB |
Output is correct |
5 |
Correct |
176 ms |
1060 KB |
Output is correct |
6 |
Correct |
222 ms |
1044 KB |
Output is correct |
7 |
Correct |
169 ms |
860 KB |
Output is correct |
8 |
Correct |
200 ms |
1076 KB |
Output is correct |
9 |
Correct |
189 ms |
860 KB |
Output is correct |
10 |
Correct |
166 ms |
860 KB |
Output is correct |
11 |
Correct |
173 ms |
1068 KB |
Output is correct |
12 |
Correct |
164 ms |
856 KB |
Output is correct |
13 |
Correct |
162 ms |
860 KB |
Output is correct |
14 |
Correct |
173 ms |
860 KB |
Output is correct |
15 |
Correct |
176 ms |
1112 KB |
Output is correct |
16 |
Correct |
235 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
170 ms |
900 KB |
Output is correct |
12 |
Correct |
174 ms |
1104 KB |
Output is correct |
13 |
Correct |
166 ms |
856 KB |
Output is correct |
14 |
Correct |
159 ms |
860 KB |
Output is correct |
15 |
Correct |
176 ms |
1060 KB |
Output is correct |
16 |
Correct |
222 ms |
1044 KB |
Output is correct |
17 |
Correct |
169 ms |
860 KB |
Output is correct |
18 |
Correct |
200 ms |
1076 KB |
Output is correct |
19 |
Correct |
189 ms |
860 KB |
Output is correct |
20 |
Correct |
166 ms |
860 KB |
Output is correct |
21 |
Correct |
173 ms |
1068 KB |
Output is correct |
22 |
Correct |
164 ms |
856 KB |
Output is correct |
23 |
Correct |
162 ms |
860 KB |
Output is correct |
24 |
Correct |
173 ms |
860 KB |
Output is correct |
25 |
Correct |
176 ms |
1112 KB |
Output is correct |
26 |
Correct |
235 ms |
856 KB |
Output is correct |
27 |
Correct |
172 ms |
1104 KB |
Output is correct |
28 |
Correct |
173 ms |
1072 KB |
Output is correct |
29 |
Correct |
168 ms |
1072 KB |
Output is correct |
30 |
Correct |
176 ms |
860 KB |
Output is correct |
31 |
Correct |
161 ms |
860 KB |
Output is correct |
32 |
Correct |
184 ms |
860 KB |
Output is correct |
33 |
Correct |
176 ms |
860 KB |
Output is correct |
34 |
Correct |
172 ms |
856 KB |
Output is correct |
35 |
Correct |
181 ms |
860 KB |
Output is correct |
36 |
Correct |
170 ms |
1076 KB |
Output is correct |