이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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";
}
# | 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... |