#include <bits/stdc++.h>
using namespace std;
struct mazan{
int a,b,cost;
};
vector <mazan> much;
int dist[5001];
int main()
{
int n,m,i,l,r,k,val;
cin>>n>>m;
for(i=0;i<=n;i++)
dist[i]=1e9;
dist[0]=0;
for(i=0;i<n;i++)
much.push_back({i,i+1,1});
for(i=1;i<=n;i++)
much.push_back({i,i-1,0});
for(i=1;i<=m;i++)
{
cin>>l>>r>>k>>val;
if(val==1)
much.push_back({r+1,l,-((r-l+1)-(k-1))});
else
much.push_back({l,r+1,(r-l+1)-k});
}
for(i=1;i<=n+1;i++)
for(auto [a,b,cost]:much)
if(dist[b]>dist[a]+cost)
dist[b]=dist[a]+cost;
for(auto [a,b,cost]:much)
if(dist[b]>dist[a]+cost)
{
cout<<-1;
return 0;
}
for(i=1;i<=n;i++)
cout<<dist[i]-dist[i-1]<<" ";
return 0;
}
Compilation message
restore.cpp: In function 'int main()':
restore.cpp:28:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
28 | for(auto [a,b,cost]:much)
| ^
restore.cpp:31:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
31 | for(auto [a,b,cost]:much)
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
888 KB |
Output is correct |
2 |
Correct |
93 ms |
916 KB |
Output is correct |
3 |
Correct |
101 ms |
916 KB |
Output is correct |
4 |
Correct |
107 ms |
916 KB |
Output is correct |
5 |
Correct |
329 ms |
916 KB |
Output is correct |
6 |
Correct |
308 ms |
916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
888 KB |
Output is correct |
2 |
Correct |
93 ms |
916 KB |
Output is correct |
3 |
Correct |
101 ms |
916 KB |
Output is correct |
4 |
Correct |
107 ms |
916 KB |
Output is correct |
5 |
Correct |
329 ms |
916 KB |
Output is correct |
6 |
Correct |
308 ms |
916 KB |
Output is correct |
7 |
Correct |
111 ms |
916 KB |
Output is correct |
8 |
Correct |
107 ms |
916 KB |
Output is correct |
9 |
Correct |
108 ms |
916 KB |
Output is correct |
10 |
Correct |
93 ms |
916 KB |
Output is correct |
11 |
Correct |
350 ms |
916 KB |
Output is correct |
12 |
Correct |
341 ms |
916 KB |
Output is correct |
13 |
Correct |
93 ms |
916 KB |
Output is correct |
14 |
Correct |
105 ms |
916 KB |
Output is correct |
15 |
Correct |
101 ms |
892 KB |
Output is correct |
16 |
Correct |
114 ms |
916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
97 ms |
888 KB |
Output is correct |
12 |
Correct |
93 ms |
916 KB |
Output is correct |
13 |
Correct |
101 ms |
916 KB |
Output is correct |
14 |
Correct |
107 ms |
916 KB |
Output is correct |
15 |
Correct |
329 ms |
916 KB |
Output is correct |
16 |
Correct |
308 ms |
916 KB |
Output is correct |
17 |
Correct |
111 ms |
916 KB |
Output is correct |
18 |
Correct |
107 ms |
916 KB |
Output is correct |
19 |
Correct |
108 ms |
916 KB |
Output is correct |
20 |
Correct |
93 ms |
916 KB |
Output is correct |
21 |
Correct |
350 ms |
916 KB |
Output is correct |
22 |
Correct |
341 ms |
916 KB |
Output is correct |
23 |
Correct |
93 ms |
916 KB |
Output is correct |
24 |
Correct |
105 ms |
916 KB |
Output is correct |
25 |
Correct |
101 ms |
892 KB |
Output is correct |
26 |
Correct |
114 ms |
916 KB |
Output is correct |
27 |
Correct |
94 ms |
888 KB |
Output is correct |
28 |
Correct |
103 ms |
916 KB |
Output is correct |
29 |
Correct |
98 ms |
892 KB |
Output is correct |
30 |
Correct |
96 ms |
916 KB |
Output is correct |
31 |
Correct |
90 ms |
896 KB |
Output is correct |
32 |
Correct |
95 ms |
916 KB |
Output is correct |
33 |
Correct |
320 ms |
916 KB |
Output is correct |
34 |
Correct |
322 ms |
916 KB |
Output is correct |
35 |
Correct |
98 ms |
924 KB |
Output is correct |
36 |
Correct |
97 ms |
916 KB |
Output is correct |