# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
493856 | Alexandruabcde | Restore Array (RMI19_restore) | C++14 | 1089 ms | 972 KiB |
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;
constexpr int INF = 1000000000;
constexpr int NMAX = 5005;
typedef pair <int, int> PII;
int N, M;
vector <PII> G[NMAX];
int sp[NMAX];
void Read () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> M;
for (int i = 1; i <= M; ++ i ) {
int L, R, K, Val;
cin >> L >> R >> K >> Val;
++ L;
++ R;
int Lg = R - L + 1;
if (Val == 0) {
G[L-1].push_back({Lg-K, R});
}
else G[R].push_back({-Lg+K-1, L-1});
}
for (int i = 0; i <= N; ++ i )
sp[i] = INF;
for (int i = 1; i <= N; ++ i ) {
int L = i, R = i;
int K = 1, Lg = 1;
G[R].push_back({0, L-1});
G[L-1].push_back({1, R});
}
}
bool InQueue[NMAX];
int viz[NMAX];
bool sol;
void BFS () {
queue <int> Q;
Q.push(0);
InQueue[0] = 1;
sp[0] = 0;
while (!Q.empty()) {
int nod = Q.front();
Q.pop();
InQueue[nod] = 0;
for (auto it : G[nod]) {
int to = it.second;
int cost = it.first;
if (sp[nod] + cost < sp[to]) {
sp[to] = sp[nod] + cost;
if (!InQueue[to]) {
Q.push(to);
InQueue[to] = 1;
viz[to] ++;
}
if (viz[to] > N) {
// cout << -1 << '\n';
// return;
}
}
}
}
for (int i = 1; i <= N; ++ i )
cout << sp[i] - sp[i-1] << " ";
}
int main () {
Read();
BFS();
}
Compilation message (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... |