Submission #500931

# Submission time Handle Problem Language Result Execution time Memory
500931 2022-01-01T17:15:17 Z sidon Painting Walls (APIO20_paint) C++17
0 / 100
1500 ms 288 KB
#include <bits/stdc++.h>
using namespace std;
#define V vector<int>

int minimumInstructions(int N, int M, int K, V C, V A, vector<V> B) {
	V g[K], x(M), y(M), dp(N+1);
	int ans = 0, i, j;

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

	for(i = N; --i >= 0; x.swap(y)) {
		if(i+2 < N)
			for(int s : g[C[i+2]]) x[s] = 0;

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

	for(dp[N] = dp[i=0]; i < N; i = j, ans++)
		for(j = min(N, i+M); j >= i && !dp[j]; --j)
			if(i == j) return -1;

	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Execution timed out 1578 ms 204 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Execution timed out 1578 ms 204 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Execution timed out 1578 ms 204 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Execution timed out 1578 ms 204 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Execution timed out 1578 ms 204 KB Time limit exceeded
4 Halted 0 ms 0 KB -