This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define vt vector
#define pb push_back
#define pii pair<int, int>
#define sz(v) (int)v.size()
#define fi first
#define se second
using namespace std;
const ll base = 107, mod = 1e9 + 7, mxv = 1e4 + 5, inf = 1e9;
const int mxn = 5e3 + 5, N = 3e6 + 5;
int n, m;
int dis[mxn + 1];
bool vis[mxn + 1];
struct th{
int u, v, w;
};
vt<th>edge;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 0; i < m; i++){
int l, r, k, v; cin >> l >> r >> k >> v;
l++; r++;
if(v == 1){
//pref[r] - k >= pref[l - 1]
k = (r - l + 1) - k + 1;
edge.pb({r, l - 1, -k});
//cout << r << " " << l - 1 << " " << -k << "\n";
}else{
k = (r - l + 1) - k;
edge.pb({l - 1, r, k});
// cout << l - 1 << " " << r << " " << k << "\n";
}
}
for(int i = 1; i <= n; i++){
edge.pb({i, i - 1, 0});
}
for(int i = 1; i <= n; i++)dis[i] = inf;
dis[0] = 0;
bool no = 0;
for(int i = 1; i <= n + 1; i++){
for(auto [u, v, w]: edge){
if(dis[v] > dis[u] + w){
dis[v] = dis[u] + w;
if(i == n + 1)no = 1;
}
}
}
for(int i = 1; i <= n; i++){
if(dis[i] == inf)dis[i] = dis[i - 1];
}
if(no)cout << -1 << "\n";
else{
for(int i = 1; i <= n; i++)cout << dis[i] - dis[i - 1] << " ";
}
}
Compilation message (stderr)
restore.cpp: In function 'int main()':
restore.cpp:43:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
43 | for(auto [u, v, w]: edge){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |