Submission #493860

# Submission time Handle Problem Language Result Execution time Memory
493860 2021-12-13T08:24:30 Z Alexandruabcde Restore Array (RMI19_restore) C++14
20 / 100
600 ms 968 KB
#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 length[NMAX];
bool sol;

void BFS () {
    queue <int> Q;

    Q.push(0);
    InQueue[0] = 1;
    sp[0] = 0;
    length[0] = 1;

    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;
                length[to] = length[nod] + 1;

                if (length[to] > N) {
                    cout << -1 << '\n';
                    return;
                }

                if (!InQueue[to]) {
                    Q.push(to);
                    InQueue[to] = 1;
                }
            }
        }
    }

    for (int i = 1; i <= N; ++ i )
        cout << sp[i] - sp[i-1] << " ";
}

int main () {
    Read();
    BFS();
}

Compilation message

restore.cpp: In function 'void Read()':
restore.cpp:40:13: warning: unused variable 'K' [-Wunused-variable]
   40 |         int K = 1, Lg = 1;
      |             ^
restore.cpp:40:20: warning: unused variable 'Lg' [-Wunused-variable]
   40 |         int K = 1, Lg = 1;
      |                    ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 764 KB Output is correct
2 Correct 17 ms 716 KB Output is correct
3 Correct 15 ms 716 KB Output is correct
4 Correct 12 ms 768 KB Output is correct
5 Correct 408 ms 800 KB Output is correct
6 Correct 436 ms 784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 764 KB Output is correct
2 Correct 17 ms 716 KB Output is correct
3 Correct 15 ms 716 KB Output is correct
4 Correct 12 ms 768 KB Output is correct
5 Correct 408 ms 800 KB Output is correct
6 Correct 436 ms 784 KB Output is correct
7 Correct 12 ms 716 KB Output is correct
8 Correct 12 ms 844 KB Output is correct
9 Correct 22 ms 968 KB Output is correct
10 Correct 12 ms 956 KB Output is correct
11 Execution timed out 1054 ms 844 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 13 ms 764 KB Output is correct
12 Correct 17 ms 716 KB Output is correct
13 Correct 15 ms 716 KB Output is correct
14 Correct 12 ms 768 KB Output is correct
15 Correct 408 ms 800 KB Output is correct
16 Correct 436 ms 784 KB Output is correct
17 Correct 12 ms 716 KB Output is correct
18 Correct 12 ms 844 KB Output is correct
19 Correct 22 ms 968 KB Output is correct
20 Correct 12 ms 956 KB Output is correct
21 Execution timed out 1054 ms 844 KB Time limit exceeded
22 Halted 0 ms 0 KB -