#include<bits/stdc++.h>
using namespace std;
//ifstream fin("input.in");
//#define cin fin
int cnt0[5005];
vector<pair<int,int>> con[5005];
int n,m;
void calc_cnt0()
{
deque<int> dq;
dq.push_back(0);
while(!dq.empty())
{
int nod = dq.front();
dq.pop_front();
for(auto x:con[nod])
{
int adj = x.first;
if(cnt0[adj] < cnt0[nod] + x.second)
{
if(adj==0)
{
cout<<-1;
exit(0);
}
cnt0[adj] = cnt0[nod] + x.second;
dq.push_back(adj);
}
}
}
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>m;
int l,r,k,val;
for(int i=0;i<m;i++)
{
cin>>l>>r>>k>>val;
l++;
r++;
if(val==0)
{
con[l-1].push_back({r,k});
}
else
{
con[r].push_back({l-1,1-k});
}
}
for(int i=1;i<=n;i++)
{
cnt0[i]=-1;
con[i].push_back({i-1,-1});
con[i-1].push_back({i,0});
}
calc_cnt0();
for(int i=0;i<=n;i++)
{
for(auto x:con[i])
{
if(cnt0[x.first] < cnt0[i] + x.second)
{
cout<<-1;
return 0;
}
}
}
for(int i=1;i<=n;i++)
{
if(cnt0[i]==cnt0[i-1])
cout<<1<<" ";
else
cout<<0<<" ";
}
return 0;
}
/**
restrictia l,r,k,0:
cnt0[r] - cnt0[l-1] >= k
cnt0[r] >= k + cnt0[l-1] *******
cnt0[l-1] <= cnt0[r] - k
restrictia l,r,k,1:
cnt0[r] - cnt0[l-1] <= k
cnt0[r] <= k + cnt0[l-1]
cnt0[l-1] >= cnt0[r] - k *****
cnt0[i-1] >= cnt0[i] - 1
cnt0[i] >= cnt0[i-1] + 0
avem doar restrictii dinastea
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
548 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
824 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
856 KB |
Output is correct |
2 |
Correct |
9 ms |
860 KB |
Output is correct |
3 |
Correct |
8 ms |
856 KB |
Output is correct |
4 |
Correct |
7 ms |
856 KB |
Output is correct |
5 |
Correct |
4 ms |
856 KB |
Output is correct |
6 |
Correct |
3 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
856 KB |
Output is correct |
2 |
Correct |
9 ms |
860 KB |
Output is correct |
3 |
Correct |
8 ms |
856 KB |
Output is correct |
4 |
Correct |
7 ms |
856 KB |
Output is correct |
5 |
Correct |
4 ms |
856 KB |
Output is correct |
6 |
Correct |
3 ms |
856 KB |
Output is correct |
7 |
Correct |
9 ms |
856 KB |
Output is correct |
8 |
Correct |
8 ms |
860 KB |
Output is correct |
9 |
Correct |
12 ms |
856 KB |
Output is correct |
10 |
Correct |
8 ms |
860 KB |
Output is correct |
11 |
Correct |
3 ms |
856 KB |
Output is correct |
12 |
Correct |
3 ms |
856 KB |
Output is correct |
13 |
Correct |
8 ms |
856 KB |
Output is correct |
14 |
Correct |
12 ms |
856 KB |
Output is correct |
15 |
Correct |
20 ms |
856 KB |
Output is correct |
16 |
Correct |
69 ms |
1080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
548 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
824 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
8 ms |
856 KB |
Output is correct |
12 |
Correct |
9 ms |
860 KB |
Output is correct |
13 |
Correct |
8 ms |
856 KB |
Output is correct |
14 |
Correct |
7 ms |
856 KB |
Output is correct |
15 |
Correct |
4 ms |
856 KB |
Output is correct |
16 |
Correct |
3 ms |
856 KB |
Output is correct |
17 |
Correct |
9 ms |
856 KB |
Output is correct |
18 |
Correct |
8 ms |
860 KB |
Output is correct |
19 |
Correct |
12 ms |
856 KB |
Output is correct |
20 |
Correct |
8 ms |
860 KB |
Output is correct |
21 |
Correct |
3 ms |
856 KB |
Output is correct |
22 |
Correct |
3 ms |
856 KB |
Output is correct |
23 |
Correct |
8 ms |
856 KB |
Output is correct |
24 |
Correct |
12 ms |
856 KB |
Output is correct |
25 |
Correct |
20 ms |
856 KB |
Output is correct |
26 |
Correct |
69 ms |
1080 KB |
Output is correct |
27 |
Correct |
5 ms |
856 KB |
Output is correct |
28 |
Correct |
4 ms |
856 KB |
Output is correct |
29 |
Correct |
5 ms |
856 KB |
Output is correct |
30 |
Correct |
5 ms |
856 KB |
Output is correct |
31 |
Correct |
5 ms |
856 KB |
Output is correct |
32 |
Correct |
5 ms |
856 KB |
Output is correct |
33 |
Correct |
3 ms |
856 KB |
Output is correct |
34 |
Correct |
3 ms |
856 KB |
Output is correct |
35 |
Correct |
5 ms |
856 KB |
Output is correct |
36 |
Correct |
5 ms |
1012 KB |
Output is correct |