#include <bits/stdc++.h>
using namespace std;
const int k_N = 5000 + 3;
const int k_M = 10000 + 3;
const int k_Inf = 1e9 + 3;
int n, m;
vector<array<int, 3>> edges;
int prefix[k_N];
bool bellman_ford(){
prefix[0] = 0;
for(int i = 1; i <= n; ++i)
prefix[i] = k_Inf;
for(int i = 0; i < n; ++i){
for(auto &edge: edges){
int new_prefix = prefix[edge[0]] + edge[2];
prefix[edge[1]] = min(new_prefix, prefix[edge[1]]);
}
}
for(auto &edge: edges){
int new_prefix = prefix[edge[0]] + edge[2];
if(new_prefix < prefix[edge[1]])
return false;
}
return true;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i = 1; i <= n; ++i){
edges.push_back({i - 1, i, 1});
edges.push_back({i, i - 1, 0});
}
for(int i = 0; i < m; ++i){
int l, r, k, value;
cin >> l >> r >> k >> value;
l++, r++;
if(value == 0)
edges.push_back({l - 1, r, (r - l + 1) - k});
else if(value == 1)
edges.push_back({r, l - 1, -((r - l + 1) - k + 1)});
}
if(!bellman_ford()){
cout << "-1\n";
return 0;
}
for(int i = n; i >= 1; --i)
prefix[i] -= prefix[i - 1];
for(int i = 1; i <= n; ++i)
cout << prefix[i] << " ";
cout << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
349 ms |
960 KB |
Output is correct |
2 |
Correct |
350 ms |
1012 KB |
Output is correct |
3 |
Correct |
351 ms |
1008 KB |
Output is correct |
4 |
Correct |
353 ms |
1012 KB |
Output is correct |
5 |
Correct |
349 ms |
960 KB |
Output is correct |
6 |
Correct |
346 ms |
960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
349 ms |
960 KB |
Output is correct |
2 |
Correct |
350 ms |
1012 KB |
Output is correct |
3 |
Correct |
351 ms |
1008 KB |
Output is correct |
4 |
Correct |
353 ms |
1012 KB |
Output is correct |
5 |
Correct |
349 ms |
960 KB |
Output is correct |
6 |
Correct |
346 ms |
960 KB |
Output is correct |
7 |
Correct |
357 ms |
1012 KB |
Output is correct |
8 |
Correct |
354 ms |
1012 KB |
Output is correct |
9 |
Correct |
360 ms |
1012 KB |
Output is correct |
10 |
Correct |
357 ms |
960 KB |
Output is correct |
11 |
Correct |
352 ms |
1088 KB |
Output is correct |
12 |
Correct |
353 ms |
960 KB |
Output is correct |
13 |
Correct |
347 ms |
1088 KB |
Output is correct |
14 |
Correct |
361 ms |
1012 KB |
Output is correct |
15 |
Correct |
366 ms |
1088 KB |
Output is correct |
16 |
Correct |
378 ms |
960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
349 ms |
960 KB |
Output is correct |
12 |
Correct |
350 ms |
1012 KB |
Output is correct |
13 |
Correct |
351 ms |
1008 KB |
Output is correct |
14 |
Correct |
353 ms |
1012 KB |
Output is correct |
15 |
Correct |
349 ms |
960 KB |
Output is correct |
16 |
Correct |
346 ms |
960 KB |
Output is correct |
17 |
Correct |
357 ms |
1012 KB |
Output is correct |
18 |
Correct |
354 ms |
1012 KB |
Output is correct |
19 |
Correct |
360 ms |
1012 KB |
Output is correct |
20 |
Correct |
357 ms |
960 KB |
Output is correct |
21 |
Correct |
352 ms |
1088 KB |
Output is correct |
22 |
Correct |
353 ms |
960 KB |
Output is correct |
23 |
Correct |
347 ms |
1088 KB |
Output is correct |
24 |
Correct |
361 ms |
1012 KB |
Output is correct |
25 |
Correct |
366 ms |
1088 KB |
Output is correct |
26 |
Correct |
378 ms |
960 KB |
Output is correct |
27 |
Correct |
342 ms |
960 KB |
Output is correct |
28 |
Correct |
359 ms |
1088 KB |
Output is correct |
29 |
Correct |
354 ms |
1012 KB |
Output is correct |
30 |
Correct |
361 ms |
1012 KB |
Output is correct |
31 |
Correct |
345 ms |
1012 KB |
Output is correct |
32 |
Correct |
355 ms |
1012 KB |
Output is correct |
33 |
Correct |
352 ms |
960 KB |
Output is correct |
34 |
Correct |
348 ms |
960 KB |
Output is correct |
35 |
Correct |
362 ms |
1012 KB |
Output is correct |
36 |
Correct |
360 ms |
1012 KB |
Output is correct |