Submission #402956

#TimeUsernameProblemLanguageResultExecution timeMemory
402956promaPainting Walls (APIO20_paint)C++17
100 / 100
560 ms15060 KiB
#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[C[0]]) { dp[0][i] = 1; } mx[0] = 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; } } int last, cnt = 0, flag = 1, ans = 0; for (int i = N - 1; i >= 0; i --, cnt --) { if (mx[i] == M) { last = i; flag = 0; } if (!cnt) { if (flag) { return -1; } flag = 1; cnt = M - last + i; ans ++; } } return ans; }

Compilation message (stderr)

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:43:21: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
   43 |             cnt = M - last + i;
      |                   ~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...