#include <bits/stdc++.h>
using namespace std;
#define ll int
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll,ll>
int main() {
ll n, m;
cin >> n >> m;
vector<vector<pll>> graph(n+1);
for (ll i = 0; i < n; i++) graph[i].push_back({i+1, 1}), graph[i+1].push_back({i, 0});
for (ll i = 0; i < m; i++) {
ll l, r, k, v;
cin >> l >> r >> k >> v;
k--;
if (v == 1) {
// cout << l << ' ' << r+1 << ' ' << -((r-l+1)-k) << endl;
graph[r+1].push_back({l, k-(r-l+1)});
} else {
// cout << r+1 << ' ' << l << ' ' << (r-l+1)-k-1 << endl;
graph[l].push_back({r+1, (r-l+1)-k-1});
}
}
vll dist(n+1, 1e18);
dist[0] = 0;
bool changed = true;
for (ll i = 0; i < n+2; i++) {
// for (ll j = 0; j < n+1; j++) cout << dist[j] << ' ';
// cout << endl;
changed = false;
for (ll j = 0; j < n+1; j++) {
for (pll e : graph[j]) {
if (dist[e.first] > dist[j] + e.second) {
changed = true;
dist[e.first] = dist[j] + e.second;
}
}
}
if (!changed) break;
}
if (changed) {
cout << -1 << endl;
return 0;
}
for (ll i = 0; i < n; i++) cout << dist[i+1] - dist[i] << ' ';
cout << endl;
}
Compilation message
restore.cpp: In function 'int main()':
restore.cpp:25:19: warning: overflow in conversion from 'double' to 'std::vector<int>::value_type' {aka 'int'} changes value from '1.0e+18' to '2147483647' [-Woverflow]
25 | vll dist(n+1, 1e18);
| ^~~~
# |
Verdict |
Execution time |
Memory |
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 |
232 KB |
Output is correct |
5 |
Correct |
1 ms |
220 KB |
Output is correct |
6 |
Correct |
1 ms |
220 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
244 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
808 KB |
Output is correct |
2 |
Correct |
12 ms |
820 KB |
Output is correct |
3 |
Correct |
15 ms |
804 KB |
Output is correct |
4 |
Correct |
16 ms |
832 KB |
Output is correct |
5 |
Correct |
521 ms |
884 KB |
Output is correct |
6 |
Correct |
488 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
808 KB |
Output is correct |
2 |
Correct |
12 ms |
820 KB |
Output is correct |
3 |
Correct |
15 ms |
804 KB |
Output is correct |
4 |
Correct |
16 ms |
832 KB |
Output is correct |
5 |
Correct |
521 ms |
884 KB |
Output is correct |
6 |
Correct |
488 ms |
896 KB |
Output is correct |
7 |
Correct |
15 ms |
908 KB |
Output is correct |
8 |
Correct |
14 ms |
852 KB |
Output is correct |
9 |
Correct |
15 ms |
820 KB |
Output is correct |
10 |
Correct |
13 ms |
852 KB |
Output is correct |
11 |
Execution timed out |
682 ms |
896 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
232 KB |
Output is correct |
5 |
Correct |
1 ms |
220 KB |
Output is correct |
6 |
Correct |
1 ms |
220 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
244 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
220 KB |
Output is correct |
11 |
Correct |
14 ms |
808 KB |
Output is correct |
12 |
Correct |
12 ms |
820 KB |
Output is correct |
13 |
Correct |
15 ms |
804 KB |
Output is correct |
14 |
Correct |
16 ms |
832 KB |
Output is correct |
15 |
Correct |
521 ms |
884 KB |
Output is correct |
16 |
Correct |
488 ms |
896 KB |
Output is correct |
17 |
Correct |
15 ms |
908 KB |
Output is correct |
18 |
Correct |
14 ms |
852 KB |
Output is correct |
19 |
Correct |
15 ms |
820 KB |
Output is correct |
20 |
Correct |
13 ms |
852 KB |
Output is correct |
21 |
Execution timed out |
682 ms |
896 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |