#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define fr first
#define sc second
#define int long long
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
// restore array rmi 2019
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int nmax = 5005;
int n, m, dist[nmax];
struct item{
int l, r, val;
};
vector <item> edges;
void add_edge(int l, int r, int k, int val){
if(val == 0){
int curr = (r - l + 1) - k;
edges.push_back({l - 1, r, curr});
}
else{
edges.push_back({r, l - 1, r - l + 1 - (k - 1)});
}
}
bool bellman_ford(){
for(int i=1;i<=n+1;i++){
for(auto it : edges){
if(dist[it.r] > dist[it.l] + it.val){
dist[it.r] = dist[it.l] + it.val;
}
}
}
for(auto it : edges){
if(dist[it.r] > dist[it.l] + it.val){
return false;
}
}
return true;
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
// freopen("input.in", "r", stdin);
cin >> n >> m;
for(int i=1;i<=n;i++){
dist[i] = 1e18;
}
for(int i=0;i<n;i++){
edges.push_back({i, i+1, 1});
}
for(int i=1;i<=n;i++){
edges.push_back({i, i - 1, 0});
}
for(int i=1;i<=m;i++){
int l, r, k, val;
cin >> l >> r >> k >> val;
++l; ++r;
add_edge(l, r, k, val);
}
if(bellman_ford() == false){
rc(-1);
}
else{
for(int i=1;i<=n;i++){
cout << dist[i] - dist[i - 1] << ' ';
}
return 0;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
139 ms |
1256 KB |
Output is correct |
2 |
Correct |
143 ms |
1384 KB |
Output is correct |
3 |
Correct |
141 ms |
1384 KB |
Output is correct |
4 |
Incorrect |
142 ms |
1384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
139 ms |
1256 KB |
Output is correct |
2 |
Correct |
143 ms |
1384 KB |
Output is correct |
3 |
Correct |
141 ms |
1384 KB |
Output is correct |
4 |
Incorrect |
142 ms |
1384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |