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>
using namespace std;
#define ll long long
#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;
}
# | 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... |