Submission #402938

# Submission time Handle Problem Language Result Execution time Memory
402938 2021-05-12T14:58:16 Z proma Painting Walls (APIO20_paint) C++17
0 / 100
1 ms 204 KB
#include <bits/stdc++.h>

using namespace std;

int minimumInstructions (int N, int M, int K, vector <int> C, vector<int> A, vector <vector<int>> B) {
    vector <int> contractor[K];
    for (int i = 0; i < M; i ++) {
        for (int j = 0; j < A[i]; j ++) {
            contractor[B[i][j]].push_back(i);
        }
    }

    int dp[2][M], mx[N];
    memset(dp, 0, sizeof(dp));
    memset(mx, 0, sizeof(mx));

    for (auto i: contractor[0]) {
        dp[0][i] = 1;
    }

    for (int i = 1; i < N; i ++) {
        for (auto j: contractor[C[i]]) {
            dp[i & 1][j] = min(dp[!(i & 1)][(j - 1 + M) % M] + 1, M);
            mx[i] = max(mx[i], dp[i & 1][j]);
        }
        for (auto j: contractor[C[i-1]]) {
            dp[!(i & 1)][j] = 0;
        }
    }

    if (mx[N - 1] != M) {
        return -1;
    }
    int last, cnt = M - 1, flag = 1, ans = 1;
    for (int i = N - 2; i >= 0; i --, cnt --) {
        if (mx[i] == M) {
            last = i;
            flag = 0;
        }
        if (!cnt) {
            if (flag) {
                return -1;
            }
            flag = 1;
            cnt = M - last + i + 1;
            ans ++;
        }
    }

    return ans;
}

Compilation message

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:45:21: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |             cnt = M - last + i + 1;
      |                   ~~^~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -