제출 #873094

#제출 시각아이디문제언어결과실행 시간메모리
873094nskybytskyiRestore Array (RMI19_restore)C++17
100 / 100
392 ms1108 KiB
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0)->sync_with_stdio(0); int n, m; cin >> n >> m; vector<vector<pair<int, int>>> graph(n + 1); for (int v = 0; v < n; ++v) { graph[v + 1].emplace_back(v, 0); graph[v].emplace_back(v + 1, 1); } while (m--) { int l, r, k, v; cin >> l >> r >> k >> v; if (v) { graph[r + 1].emplace_back(l, k - r + l - 2); } else { graph[l].emplace_back(r + 1, r - l + 1 - k); } } const auto inf = numeric_limits<int>::max() >> 1; vector<int> distance(n + 1, inf); distance[0] = 0; bool exists = true; for (int phase = 0; phase <= n; ++phase) { exists = true; for (int u = 0; u < n; ++u) { if (distance[u] < inf) { for (const auto& [v, w] : graph[u]) { if (distance[v] > distance[u] + w) { exists = false; distance[v] = distance[u] + w; } } } } } if (!exists) { cout << -1 << '\n'; } else { for (int v = 0; v < n; ++v) { cout << distance[v + 1] - distance[v] << ' '; } cout << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...