# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
555865 | mihnea_tudor | Restore Array (RMI19_restore) | C++17 | 593 ms | 904 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define NMAX ((int)5e3)
#define INF ((int)1e9)
using namespace std;
struct edge {
int dest, cost;
};
int n, m;
vector<edge> a[NMAX + 1];
int dist[NMAX + 1];
bool bellmanford() {
for (int i = 1; i <= n; ++i) {
dist[i] = INF;
}
dist[0] = 0;
for (int cnt = 0; cnt < n; ++cnt) {
// Check all edges
for (int node = 0; node <= n; ++node) {
for (auto it = a[node].begin(); it != a[node].end(); ++it) {
edge next = *it;
if (dist[node] + next.cost < dist[next.dest]) {
dist[next.dest] = dist[node] + next.cost;
}
}
}
}
for (int node = 0; node <= n; ++node) {
for (auto it = a[node].begin(); it != a[node].end(); ++it) {
edge next = *it;
if (dist[node] + next.cost < dist[next.dest]) {
return false;
}
}
}
return true;
}
void add_constraint(int left, int right, int k, int val) {
if (val == 0) {
a[left - 1].push_back({right, (right - left + 1) - k});
} else {
a[right].push_back({left - 1, -((right - left + 1) - (k - 1))});
}
}
int main(void) {
scanf("%d %d", &n, &m);
for (int i = 0; i < m; ++i) {
int left, right, k, val;
scanf("%d %d %d %d", &left, &right, &k, &val);
++left; ++right;
add_constraint(left, right, k, val);
}
for (int i = 1; i <= n; ++i) {
a[i - 1].push_back({i, 1});
a[i].push_back({i - 1, 0});
}
if (!bellmanford()) {
printf("-1\n");
return 0;
}
for (int i = 1; i <= n; ++i) {
printf("%d ", dist[i] - dist[i - 1]);
}
printf("\n");
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |