제출 #402954

#제출 시각아이디문제언어결과실행 시간메모리
402954proma벽 칠하기 (APIO20_paint)C++17
0 / 100
1 ms204 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; } 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; }

컴파일 시 표준 에러 (stderr) 메시지

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:42:21: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
   42 |             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...