#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
using namespace std;
const int N=2e5+5,inf = 1e9+7;
int t,n,m,dist[N],upd[N];
vector<pair<pair<int,int>,int> > edges;
main(){
cin>>n>>m;
for(int i=0;i<n;i++) {
edges.push_back({{i,i+1},1});
edges.push_back({{i+1,i},0});
}
while(m--){
int l,r,k,val;
cin>>l>>r>>k>>val;
l++; r++;
if(val==0) {
edges.push_back({{l-1,r},r-l+1-k});
}
else edges.push_back({{r,l-1}, - (r-l+1-k+1)});
}
for(int i=1;i<=n;i++) dist[i] = inf;
while(true) {
int f=0;
for(int i=0;i<edges.size();i++){
int u = edges[i].f.f;
int v = edges[i].f.s;
if(dist[v] > dist[u] + edges[i].s) {
f = 1;
dist[v] = dist[u] + edges[i].s;
upd[v]++;
if(upd[v]==n) {
cout<<-1;
return 0;
}
}
}
if(!f) break;
}
for(int i=1;i<=n;i++) {
cout<<dist[i]-dist[i-1]<<" ";
}
}
Compilation message
restore.cpp:9:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
9 | main(){
| ^~~~
restore.cpp: In function 'int main()':
restore.cpp:29:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i=0;i<edges.size();i++){
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
1096 KB |
Output is correct |
2 |
Correct |
14 ms |
1188 KB |
Output is correct |
3 |
Correct |
14 ms |
1096 KB |
Output is correct |
4 |
Correct |
13 ms |
1124 KB |
Output is correct |
5 |
Correct |
78 ms |
1096 KB |
Output is correct |
6 |
Correct |
76 ms |
1096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
1096 KB |
Output is correct |
2 |
Correct |
14 ms |
1188 KB |
Output is correct |
3 |
Correct |
14 ms |
1096 KB |
Output is correct |
4 |
Correct |
13 ms |
1124 KB |
Output is correct |
5 |
Correct |
78 ms |
1096 KB |
Output is correct |
6 |
Correct |
76 ms |
1096 KB |
Output is correct |
7 |
Correct |
16 ms |
1096 KB |
Output is correct |
8 |
Correct |
14 ms |
1140 KB |
Output is correct |
9 |
Correct |
14 ms |
1096 KB |
Output is correct |
10 |
Correct |
13 ms |
1096 KB |
Output is correct |
11 |
Correct |
85 ms |
1156 KB |
Output is correct |
12 |
Correct |
89 ms |
1096 KB |
Output is correct |
13 |
Correct |
13 ms |
1096 KB |
Output is correct |
14 |
Correct |
12 ms |
1172 KB |
Output is correct |
15 |
Correct |
15 ms |
1144 KB |
Output is correct |
16 |
Correct |
57 ms |
1196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
15 ms |
1096 KB |
Output is correct |
12 |
Correct |
14 ms |
1188 KB |
Output is correct |
13 |
Correct |
14 ms |
1096 KB |
Output is correct |
14 |
Correct |
13 ms |
1124 KB |
Output is correct |
15 |
Correct |
78 ms |
1096 KB |
Output is correct |
16 |
Correct |
76 ms |
1096 KB |
Output is correct |
17 |
Correct |
16 ms |
1096 KB |
Output is correct |
18 |
Correct |
14 ms |
1140 KB |
Output is correct |
19 |
Correct |
14 ms |
1096 KB |
Output is correct |
20 |
Correct |
13 ms |
1096 KB |
Output is correct |
21 |
Correct |
85 ms |
1156 KB |
Output is correct |
22 |
Correct |
89 ms |
1096 KB |
Output is correct |
23 |
Correct |
13 ms |
1096 KB |
Output is correct |
24 |
Correct |
12 ms |
1172 KB |
Output is correct |
25 |
Correct |
15 ms |
1144 KB |
Output is correct |
26 |
Correct |
57 ms |
1196 KB |
Output is correct |
27 |
Correct |
14 ms |
1224 KB |
Output is correct |
28 |
Correct |
14 ms |
1096 KB |
Output is correct |
29 |
Correct |
15 ms |
1180 KB |
Output is correct |
30 |
Correct |
15 ms |
1096 KB |
Output is correct |
31 |
Correct |
13 ms |
1096 KB |
Output is correct |
32 |
Correct |
12 ms |
1096 KB |
Output is correct |
33 |
Correct |
82 ms |
1096 KB |
Output is correct |
34 |
Correct |
71 ms |
1132 KB |
Output is correct |
35 |
Correct |
14 ms |
1096 KB |
Output is correct |
36 |
Correct |
13 ms |
1180 KB |
Output is correct |