제출 #500928

#제출 시각아이디문제언어결과실행 시간메모리
500928sidonPainting Walls (APIO20_paint)C++17
100 / 100
461 ms14804 KiB
#include <bits/stdc++.h>
using namespace std;
#include "paint.h"
#define V vector

int minimumInstructions(int N, int M, int K, V<int> C, V<int> A, V<V<int>> B) {
	V<int> cand[K], x(M), y(M), dp(N+1);

	for(int i = 0; i < M; i++)
		for(int &j : B[i]) cand[j].push_back(i);

	for(int i = N; --i >= 0; swap(x, y)) {
		if(i+2 < N)
			for(int j : cand[C[i+2]]) x[j] = 0;

		for(int j : cand[C[i]]) 
			if((x[j] = 1 + y[(j + 1) % M]) >= M) dp[i] = 1;
	}

	int ans = 0; dp[N] = dp[0];

	for(int i = 0, j; i < N; i = j, ans++) {
		j = min(N, i + M);
		while(j > i && !dp[j]) --j;
		if(i == j) return -1;
	}
	return ans;
}
#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...